-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgit-subcommand.ts
More file actions
executable file
·69 lines (57 loc) · 1.6 KB
/
git-subcommand.ts
File metadata and controls
executable file
·69 lines (57 loc) · 1.6 KB
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
#!/usr/bin/env -S deno run -A
import { cliteRun, help, noCommand, subcommand, usage } from "../mod.ts";
@noCommand()
@usage("git branch [Options] [--] <branchname>")
@help("git-branch - List, create, or delete branches")
class Branch {
@help("Delete a branch.")
delete = false;
_clite_parent?: ToolWithSubcommand;
main(branchname: string) {
console.log("main branch command", {
gitDir: this._clite_parent?.gitDir,
delete: this.delete,
branchname,
});
return { branch: this, branchname };
}
}
class ToolWithSubcommand {
gitDir = ".";
@subcommand()
@help("List, create, or delete branches")
branch = Branch;
@subcommand()
commit = {
_no_command: true,
all: false,
message: "",
main() {
console.log("main commit command", this);
return this;
},
};
main(opt: string) {
console.log("main command", this, opt);
return this;
}
}
cliteRun(ToolWithSubcommand, { dontPrintResult: true });
/*
$ ./git-subcommand.ts --help
Usage: <ToolWithSubcommand file> [Options] [--] [command [command args]]
Commands:
main <opt> [default]
branch --help | [sub Options / cmd / args]
commit --help | [sub Options / cmd / args]
Options:
-h, --help Show this help [default: false]
--git-dir [default: "."]
--commit [default: [object Object]]
$ ./git-subcommand.ts branch --help
git-branch - List, create, or delete branches
Usage: git branch [Options] [--] <branchname>
Options:
-h, --help Show this help [default: false]
--delete Delete a branch. [default: false]
*/