Skip to content

Commit d1c2398

Browse files
committed
Sets default args, descriptions, and required args. Parses args with commander.
1 parent 8b98f75 commit d1c2398

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

index.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env node
2+
'use-strict';
3+
4+
const program = require('commander');
5+
6+
const defaultArgs = {
7+
themename: 'WP Theme',
8+
themeuri: 'https://github.com/dreamsicle-io/create-wp-theme',
9+
themeversion: '0.0.1',
10+
themedescription: 'This theme was generated using "create-wp-theme".',
11+
author: 'Dreamsicle',
12+
authoruri: 'https://www.dreamsicle.io',
13+
license: 'GPL-3.0',
14+
textdomain: 'wp-theme',
15+
tags: 'accessibility-ready, translation-ready',
16+
};
17+
18+
const argDescriptions = {
19+
themename: 'The theme name.',
20+
themeuri: 'The theme URI.',
21+
themeversion: 'The theme version.',
22+
themedescription: 'The theme description',
23+
author: 'The theme author.',
24+
authoruri: 'The theme author URI.',
25+
license: 'The theme license as a valid SPDX expression.',
26+
textdomain: 'The theme text domain.',
27+
tags: 'A comma separated list of valid WordPress theme repository tags.',
28+
};
29+
30+
const argAliases = {
31+
themename: 'tn',
32+
themeuri: 'tu',
33+
themeversion: 'tv',
34+
themedescription: 'td',
35+
author: 'a',
36+
authoruri: 'au',
37+
license: 'l',
38+
textdomain: 'td',
39+
tags: 't',
40+
};
41+
42+
const requiredArgs = [
43+
'themename',
44+
'textdomain',
45+
];
46+
47+
program.arguments('<file>');
48+
49+
for (var key in defaultArgs) {
50+
const defaultValue = defaultArgs[key];
51+
const alias = argAliases[key];
52+
const description = argDescriptions[key];
53+
const isRequired = (requiredArgs.indexOf(key) !== -1);
54+
program.option('-' + alias + ', --' + key + ' <' + key + '>', description);
55+
}
56+
57+
program.parse(process.argv);
58+
59+
const args = defaultArgs;
60+
for (var key in defaultArgs) {
61+
if (program[key]) {
62+
args[key] = program[key];
63+
}
64+
}
65+
66+
console.log(args);

0 commit comments

Comments
 (0)