-
Notifications
You must be signed in to change notification settings - Fork 7
/
fauxgit.js
executable file
·155 lines (130 loc) · 3.71 KB
/
fauxgit.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env node
/*
* A CLI to show how one can do two-level deep subcommands, i.e. like
* `git remote add ...`.
*/
var p = console.log;
var util = require('util');
var cmdln = require('../lib/cmdln'),
Cmdln = cmdln.Cmdln;
//---- sub CLI for `git remote`
function GitRemote(parent) {
this.parent = parent;
Cmdln.call(this, {
name: 'git remote',
desc: 'manage set of tracked repositories',
options: [
{names: ['verbose', 'v'], type: 'bool', help: 'Verbose output.'},
],
helpBody: (
'More help content blah blah.'
)
});
}
util.inherits(GitRemote, Cmdln);
GitRemote.prototype.emptyLine = function (cb) {
p('TODO: implement `git remote`');
};
GitRemote.prototype.do_add = function (subcmd, opts, args, cb) {
p('TODO: implment `git remote add`: opts=%j args=%j', opts, args)
cb();
};
GitRemote.prototype.do_add.options = [
{
names: ['t'],
helpArg: '<branch>',
type: 'string'
}
];
GitRemote.prototype.do_add.help = (
'Adds a remote named <name> for the repository ...\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} add [<options>] <name> <url>\n'
+ '\n'
+ '{{options}}'
);
GitRemote.prototype.do_rename = function (subcmd, opts, args, cb) {
p('TODO: implement `git remote rename`: opts=%j args=%j', opts, args);
cb();
};
GitRemote.prototype.do_rename.help = (
'Rename the remote named <old> to <new>.\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} rename <old> <new>\n'
);
//---- sub CLI for `git submodule`
function GitSubmodule(parent) {
this.parent = parent;
Cmdln.call(this, {
name: 'git submodule',
desc: 'Initialize, update or inspect submodules',
options: [
{names: ['quiet'], type: 'bool'}
]
});
}
util.inherits(GitSubmodule, Cmdln);
GitSubmodule.prototype.emptyLine = function (cb) {
p('TODO: implement `git submodule`');
};
GitSubmodule.prototype.do_add = function (subcmd, opts, args, cb) {
p('TODO: implment `git submodule add`: opts=%j args=%j', opts, args)
cb();
};
GitSubmodule.prototype.do_add.options = [
{
names: ['b'],
helpArg: '<branch>',
type: 'string'
}
];
GitSubmodule.prototype.do_add.help = (
'Add the given repository as a submodule at the given ...\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} add [<options>] [--] <repository> [<path>]\n'
+ '\n'
+ '{{options}}'
);
GitSubmodule.prototype.do_status = function (subcmd, opts, args, cb) {
p('TODO: implement `git submodule status`: opts=%j args=%j', opts, args);
cb();
};
GitSubmodule.prototype.do_status.help = (
'Show the status of the submodules. This will...\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} status [<options>] [--] [<path>...]\n'
);
//---- top-level CLI for `git`
function Git() {
Cmdln.call(this, {
name: 'git',
desc: 'A faux-git skeleton to show how to do sub-subcommands like '
+ '`git remote ...` with node-cmdln.',
options: [
{names: ['help', 'h'], type: 'bool', help: 'Print help and exit.'},
{names: ['version'], type: 'bool', help: 'Print version and exit.'}
]
});
}
util.inherits(Git, Cmdln);
Git.prototype.init = function (opts, args, cb) {
if (opts.version) {
p('(pretend) Git version 1.0.0');
return cb(false);
}
Cmdln.prototype.init.apply(this, arguments);
};
Git.prototype.do_config = function (subcmd, opts, args, cb) {
p('git config: opts=%j args=%j', opts, args)
cb();
};
Git.prototype.do_remote = GitRemote;
Git.prototype.do_submodule = GitSubmodule;
//---- mainline
if (require.main === module) {
cmdln.main(new Git(), {showErrStack: true});
}