Skip to content

Commit

Permalink
feat: use varargs for glob patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMalch committed Oct 27, 2020
1 parent c999791 commit 967bd35
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ npm i -g glob-zip
```
$ glob-zip --help
Usage: glob-zip [options] <outFile> [globPattern]
Usage: glob-zip [options] <outFile> <globPatterns...>
Options:
-V, --version output the version number
-g, --glob <pattern> Add a glob pattern
-a, --append Appends to the specified outFile if present (default: false)
-l, --lift <depth> Lift files the given amount of directories for the path in the zip (default: 0)
-w, --wrap [name] Define the root path within the zip, defaults to current directory name if flag is present without value
-F, --no-fail Do not fail when zip would be empty
-E, --no-empty Do not include empty directories
-d, --dry-run Do not write the final zip (default: false)
-v, --verbose Use verbose output (default: false)
-h, --help display help for command
-w, --wrap [name] Define the root path within the zip, defaults to current directory name if flag is present without value
-l, --lift [depth] Lift files the given amount of directories for the path in the zip (default: 0)
-a, --append Appends to the specified outFile if present. If not, a file with the same name would be removed. (default: false)
-F, --no-fail Do not fail when zip would be empty
-E, --no-empty Do not include empty directories
-d, --dry-run Do not write or delete any files (default: false)
-V, --verbose Use verbose output (default: false)
-v, --version output the version number
-h, --help display help for command
Examples:
$ glob-zip out.zip *.json # easiest usage
$ glob-zip out.zip -g *.json -g *.js # multiple glob patterns
$ glob-zip out.zip *.json "sp ace.txt" *.js # three glob patterns
$ glob-zip out.zip src/**/*.js --wrap backup --lift 1 # effectively renames "src" to "backup" in zip
```
15 changes: 7 additions & 8 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ function resolveWrap(value) {
}
}

// FIXME: change argument usage to "glob-zip [options] <outFile> <pattern> [patterns...]"

program
.name('glob-zip')
.arguments('<outFile> [globPattern]')
.arguments('<outFile> <globPatterns...>')
.on('option:verbose', function () {
process.env.VERBOSE = this.verbose;
})
Expand All @@ -36,16 +34,15 @@ program
console.log('');
console.log('Examples:');
console.log(' $ glob-zip out.zip *.json # easiest usage');
console.log(' $ glob-zip out.zip *.json --glob="sp ace.txt" -g *.js # three glob patterns');
console.log(' $ glob-zip out.zip *.json "sp ace.txt" *.js # three glob patterns');
console.log(' $ glob-zip out.zip src/**/*.js --wrap backup --lift 1 # effectively renames "src" to "backup" in zip');
})
.option('-g, --glob <pattern>', 'Add a glob pattern', addGlobPattern)
.option(
'-w, --wrap [name]',
'Define the root path within the zip, defaults to current directory name if flag is present without value'
)
.option(
'-l, --lift <depth>',
'-l, --lift [depth]',
'Lift files the given amount of directories for the path in the zip',
(v) => parseInt(v, 10),
0
Expand All @@ -56,9 +53,11 @@ program
.option('-d, --dry-run', 'Do not write or delete any files', false)
.option('-v, --verbose', 'Use verbose output', false)
.version(pkg.version)
.action((outFile, globPattern) => {
.action((outFile, globPatterns) => {
output = path.resolve(outFile);
addGlobPattern(globPattern);
for (const globPattern of globPatterns) {
addGlobPattern(globPattern);
}
});

program.parse(process.argv);
Expand Down

0 comments on commit 967bd35

Please sign in to comment.