|
2 | 2 |
|
3 | 3 | var async = require('grunt').util.async; |
4 | 4 | var grunt = require('grunt'); |
| 5 | +var ArgUtil = require('flopmang'); |
5 | 6 |
|
6 | 7 | module.exports = function (task, exec, done) { |
| 8 | + var argUtil = new ArgUtil(task, [ |
| 9 | + { |
| 10 | + // --format=<fmt> |
| 11 | + // 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. |
| 12 | + option: 'format', |
| 13 | + defaultValue: null, |
| 14 | + useAsFlag: true, |
| 15 | + useValue: true |
| 16 | + }, |
| 17 | + { |
| 18 | + // --prefix=<prefix>/ |
| 19 | + // Prepend <prefix>/ to each filename in the archive. |
| 20 | + option: 'prefix', |
| 21 | + defaultValue: null, |
| 22 | + useAsFlag: true, |
| 23 | + useValue: true |
| 24 | + }, |
| 25 | + { |
| 26 | + // --output=<file> |
| 27 | + // Write the archive to <file> instead of stdout. |
| 28 | + option: 'output', |
| 29 | + defaultValue: null, |
| 30 | + useAsFlag: true, |
| 31 | + useValue: true |
| 32 | + }, |
| 33 | + { |
| 34 | + // --remote=<repo> |
| 35 | + // Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository. |
| 36 | + // Note: It seems that GitHub does not support the remote archiving feature. |
| 37 | + option: 'remote', |
| 38 | + defaultValue: null, |
| 39 | + useAsFlag: true, |
| 40 | + useValue: true |
| 41 | + }, |
| 42 | + { |
| 43 | + // <tree-ish> |
| 44 | + // The tree or commit to produce an archive for. |
| 45 | + option: 'treeIsh', |
| 46 | + defaultValue: 'master', |
| 47 | + useAsFlag: false, |
| 48 | + useValue: true, |
| 49 | + required: true |
| 50 | + }, |
| 51 | + { |
| 52 | + // <path> |
| 53 | + // 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. |
| 54 | + option: 'path', |
| 55 | + defaultValue: null, |
| 56 | + useAsFlag: false, |
| 57 | + useValue: true, |
| 58 | + customValueFn: function (arg) { |
| 59 | + if (arg.value) { |
| 60 | + if (grunt.util.kindOf(arg.value) === 'string') { |
| 61 | + // Backwards compatible to <= 0.2.8. |
| 62 | + arg.value = [arg.value]; |
| 63 | + } |
| 64 | + return arg.value; |
| 65 | + } |
| 66 | + return null; |
| 67 | + } |
| 68 | + } |
| 69 | + ]); |
7 | 70 | var options = task.options({ |
8 | 71 | treeIsh: 'master' |
9 | 72 | }); |
10 | 73 |
|
11 | | - var args = ['archive']; |
12 | | - |
| 74 | + var args = ['archive'].concat(argUtil.getArgFlags()); |
13 | 75 | // git archive --format=<format> --prefix=<base_directory>/ treeIsh --output=<output file> |
14 | 76 |
|
15 | | - if (!options.treeIsh || options.treeIsh.trim() === '') { |
16 | | - done(new Error('gitarchive requires a treeIsh parameter.')); |
17 | | - return; |
18 | | - } |
19 | | - |
20 | | - // --format=<fmt> |
21 | | - // 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. |
22 | | - if (options.format && options.format.trim() !== '') { |
23 | | - args.push('--format'); |
24 | | - args.push(options.format.trim()); |
25 | | - } |
26 | | - |
27 | | - // --prefix=<prefix>/ |
28 | | - // Prepend <prefix>/ to each filename in the archive. |
29 | | - if (options.prefix && options.prefix.trim() !== '') { |
30 | | - args.push('--prefix'); |
31 | | - args.push(options.prefix.trim()); |
32 | | - } |
33 | | - |
34 | | - // --output=<file> |
35 | | - // Write the archive to <file> instead of stdout. |
36 | | - if (options.output && options.output.trim() !== '') { |
37 | | - args.push('--output'); |
38 | | - args.push(options.output.trim()); |
39 | | - } |
40 | | - |
41 | | - // --remote=<repo> |
42 | | - // Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository. |
43 | | - // Note: It seems that GitHub does not support the remote archiving feature. |
44 | | - if (options.remote && options.remote.trim() !== '') { |
45 | | - args.push('--remote'); |
46 | | - args.push(options.remote.trim()); |
47 | | - } |
48 | | - |
49 | | - // <tree-ish> |
50 | | - // The tree or commit to produce an archive for. |
51 | | - args.push(options.treeIsh.trim()); |
52 | | - |
53 | | - // <path> |
54 | | - // 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. |
55 | | - if (options.path) { |
56 | | - if (grunt.util.kindOf(options.path) === 'string') { |
57 | | - // Backwards compatible to <= 0.2.8. |
58 | | - options.path = [options.path]; |
59 | | - } |
60 | | - |
61 | | - args = args.concat(options.path); |
62 | | - } |
63 | | - |
64 | 77 | // Add callback |
65 | 78 | args.push(done); |
66 | 79 |
|
|
0 commit comments