Skip to content

Commit

Permalink
Fix passing cacheControl json from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaNarie committed Dec 4, 2018
1 parent f610022 commit 78c78f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,25 @@ Required:
-r, --remote-path The remote path in the bucket to upload the files to. [string] [required]
Options:
-d, --dry-run Do a dry run, don't do any upload. [boolean] [default: false]
-C, --concurrency The amount of simultaneous uploads, increase on faster internet connection. [number] [default: 100]
-g, --glob A glob on filename level to filter the files to upload [string] [default: "*.*"]
-c, --config The AWS config json path to load S3 credentials with loadFromPath. [string]
-h, --help Show help [boolean]
-d, --dry-run Do a dry run, don't do any upload. [boolean] [default: false]
-C, --concurrency The amount of simultaneous uploads, increase on faster internet connection.
[number] [default: 100]
-g, --glob A glob on filename level to filter the files to upload [string] [default: "*.*"]
-a, --cache-control Cache control for uploaded files, can be string for single value or list of glob settings
[string] [default: ""]
-c, --config The AWS config json path to load S3 credentials with loadFromPath. [string]
-h, --help Show help [boolean]
Examples:
cli.js upload -b bucket-name -p ./files -r /data Upload files from a local folder to a s3 bucket path
cli.js upload -d ... Dry run upload
cli.js -b bucket-name -p ./files -r /data Upload files from a local folder to a s3 bucket path
cli.js ... -a "max-age: 300" Set cache-control for all files
cli.js ... -a '{ "**/*.json": "max-age: 300", "**/*.*": Upload files from a local folder to a s3 bucket path
"3600" }'
cli.js -d ... Dry run upload
for more information about AWS authentication, please visit
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html
```

### API
Expand Down
10 changes: 10 additions & 0 deletions src/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ yargs
describe: 'Cache control for uploaded files, can be string for single value or list of glob settings',
type: 'string',
nargs: 1,
coerce: (value) => {
try {
// try to see if it's an object
const cc = JSON.parse(value);
if (typeof cc === 'object') {
return cc;
}
} catch (e) { }
return value;
}
})
// NOTE: For more info, see https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-json-file.html
.option('c', {
Expand Down

0 comments on commit 78c78f0

Please sign in to comment.