Skip to content

Instantly share code, notes, and snippets.

@vvakame
Created January 4, 2015 13:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vvakame/f0daed7266f489de5c74 to your computer and use it in GitHub Desktop.
Save vvakame/f0daed7266f489de5c74 to your computer and use it in GitHub Desktop.
commander https://www.npmjs.com/package/commander をTypeScriptになじみやすく書きなおす例
/// <reference path="../typings/node/node.d.ts" />
import command = require("../lib/index");
var root = command
.create<{replace: boolean; config: string[];}>()
.description("foo bar")
.option("-r, --replace", "replace files")
.option("-c, --config <file>", "specified config file")
.action((opts, rest) => {
console.log("root action");
console.log(opts);
console.log(rest);
});
var remote = root
.subCommand<{verbose: boolean;}>("remote")
.description("about remote repos")
.option("-v, --verbose")
.action((opts, rest)=> {
console.log("remote action");
console.log(opts);
console.log(rest);
});
remote
.subCommand("add")
.action((opts, rest)=> {
return remote
.exec()
.then(()=> {
console.log("remote add action");
console.log(opts);
console.log(rest);
var rootOpts = root.parsedOpts;
var remoteOpts = remote.parsedOpts;
console.log("!", rootOpts, remoteOpts, opts);
});
});
command.exec(root, process.argv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment