-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmkdir.js
76 lines (64 loc) · 2.37 KB
/
mkdir.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"use strict";
var argv = require ("../lib").createParser ({ once: true })
.description ("Create the DIRECTORY(ies), if they do not already exist.")
.usages (["mkdir [OPTION]... DIRECTORY..."])
.allowUndefinedArguments ()
.on ("start", function (argv){
argv.dirs = [];
})
.on ("argument", function (argv, argument, ignore){
argv.dirs.push (argument);
ignore ();
})
.body ()
.text ("Mandatory arguments to long options are mandatory for short " +
"options too.")
.option ({ short: "m", long: "mode", metavar: "MODE",
description: "Set file mode (as in chmod), not a=rwx - umask" })
.option ({ short: "p", long: "parents", description: "No error if " +
"existing, make parent directories as needed" })
.option ({ short: "v", long: "verbose",
description: "Print a message for each created directory" })
.option ({ short: "Z", long: "context", metavar: "CTX",
description: "Set the SELinux security cntext of each created " +
"directory to CTX" })
.help ({ short: false })
.version ("v1.2.3", { short: false })
.argv ();
console.log (argv);
/*
$ node mkdir.js --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE Set file mode (as in chmod), not a=rwx - umask
-p, --parents No error if existing, make parent directories as
needed
-v, --verbose Print a message for each created directory
-Z, --context=CTX Set the SELinux security cntext of each created
directory to CTX
--help Display this help message and exit
--version Output version information and exit
--------------------------------------------------------------------------------
$ node mkdir.js -p a b c
{
mode: null,
parents: true,
verbose: false,
context: null,
help: false,
version: false,
dirs: ["a", "b", "c" ]
}
--------------------------------------------------------------------------------
$ node mkdir.js -- --help
{
mode: null,
parents: false,
verbose: false,
context: null,
help: false,
version: false,
dirs: ["--help" ]
}
*/