Created
January 4, 2015 13:20
-
-
Save vvakame/f0daed7266f489de5c74 to your computer and use it in GitHub Desktop.
commander https://www.npmjs.com/package/commander をTypeScriptになじみやすく書きなおす例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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