-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automate conversion of options to arguments #70
Changes from all commits
dbff565
b62b1fa
b72ecff
90775e0
0544f69
a0550b8
70faea1
a6dff00
2d9bb87
10e62a6
40bb112
17aef85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,65 +2,78 @@ | |
|
||
var async = require('grunt').util.async; | ||
var grunt = require('grunt'); | ||
var ArgUtil = require('flopmang'); | ||
|
||
module.exports = function (task, exec, done) { | ||
var argUtil = new ArgUtil(task, [ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each object contains configuration values that affect how the CLI flags are generated. |
||
// --format=<fmt> | ||
// Format of the resulting archive: tar or zip. If this option is not given, and the output file is specified, the format is inferred from the filename if possible (e.g. writing to "foo.zip" makes the output to be in the zip format). Otherwise the output format is tar. | ||
option: 'format', | ||
defaultValue: null, | ||
useAsFlag: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If useAsFlag is true, then the option's label will be included in the args. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good stuff! |
||
useValue: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If useValue is true, then the option's value will be included in the args. |
||
}, | ||
{ | ||
// --prefix=<prefix>/ | ||
// Prepend <prefix>/ to each filename in the archive. | ||
option: 'prefix', | ||
defaultValue: null, | ||
useAsFlag: true, | ||
useValue: true | ||
}, | ||
{ | ||
// --output=<file> | ||
// Write the archive to <file> instead of stdout. | ||
option: 'output', | ||
defaultValue: null, | ||
useAsFlag: true, | ||
useValue: true | ||
}, | ||
{ | ||
// --remote=<repo> | ||
// Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository. | ||
// Note: It seems that GitHub does not support the remote archiving feature. | ||
option: 'remote', | ||
defaultValue: null, | ||
useAsFlag: true, | ||
useValue: true | ||
}, | ||
{ | ||
// <tree-ish> | ||
// The tree or commit to produce an archive for. | ||
option: 'treeIsh', | ||
defaultValue: 'master', | ||
useAsFlag: false, | ||
useValue: true, | ||
required: true | ||
}, | ||
{ | ||
// <path> | ||
// Without an optional path parameter, all files and subdirectories of the current working directory are included in the archive. If one or more paths are specified, only these are included. | ||
option: 'path', | ||
defaultValue: null, | ||
useAsFlag: false, | ||
useValue: true, | ||
customValueFn: function (arg) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Custom function to maintain backwards compatibility There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not strictly needed, but nice. |
||
if (arg.value) { | ||
if (grunt.util.kindOf(arg.value) === 'string') { | ||
// Backwards compatible to <= 0.2.8. | ||
arg.value = [arg.value]; | ||
} | ||
return arg.value; | ||
} | ||
return null; | ||
} | ||
} | ||
]); | ||
var options = task.options({ | ||
treeIsh: 'master' | ||
}); | ||
|
||
var args = ['archive']; | ||
|
||
var args = ['archive'].concat(argUtil.getArgFlags()); | ||
// git archive --format=<format> --prefix=<base_directory>/ treeIsh --output=<output file> | ||
|
||
if (!options.treeIsh || options.treeIsh.trim() === '') { | ||
done(new Error('gitarchive requires a treeIsh parameter.')); | ||
return; | ||
} | ||
|
||
// --format=<fmt> | ||
// Format of the resulting archive: tar or zip. If this option is not given, and the output file is specified, the format is inferred from the filename if possible (e.g. writing to "foo.zip" makes the output to be in the zip format). Otherwise the output format is tar. | ||
if (options.format && options.format.trim() !== '') { | ||
args.push('--format'); | ||
args.push(options.format.trim()); | ||
} | ||
|
||
// --prefix=<prefix>/ | ||
// Prepend <prefix>/ to each filename in the archive. | ||
if (options.prefix && options.prefix.trim() !== '') { | ||
args.push('--prefix'); | ||
args.push(options.prefix.trim()); | ||
} | ||
|
||
// --output=<file> | ||
// Write the archive to <file> instead of stdout. | ||
if (options.output && options.output.trim() !== '') { | ||
args.push('--output'); | ||
args.push(options.output.trim()); | ||
} | ||
|
||
// --remote=<repo> | ||
// Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository. | ||
// Note: It seems that GitHub does not support the remote archiving feature. | ||
if (options.remote && options.remote.trim() !== '') { | ||
args.push('--remote'); | ||
args.push(options.remote.trim()); | ||
} | ||
|
||
// <tree-ish> | ||
// The tree or commit to produce an archive for. | ||
args.push(options.treeIsh.trim()); | ||
|
||
// <path> | ||
// Without an optional path parameter, all files and subdirectories of the current working directory are included in the archive. If one or more paths are specified, only these are included. | ||
if (options.path) { | ||
if (grunt.util.kindOf(options.path) === 'string') { | ||
// Backwards compatible to <= 0.2.8. | ||
options.path = [options.path]; | ||
} | ||
|
||
args = args.concat(options.path); | ||
} | ||
|
||
// Add callback | ||
args.push(done); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new module that I created.