Skip to content

Commit

Permalink
docs(example): add command hierarchy example (yargs#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmx authored and bcoe committed Mar 4, 2018
1 parent 11691a6 commit fb62d88
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions example/cmds/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
exports.command = 'init [dir]'
exports.desc = 'Create an empty repo'
exports.builder = {
dir: {
default: '.'
}
}
exports.handler = function (argv) {
console.log('init called for dir', argv.dir)
}
6 changes: 6 additions & 0 deletions example/cmds/remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exports.command = 'remote <command>'
exports.description = 'Manage set of tracked repos'
exports.builder = function (yargs) {
return yargs.commandDir('remote_cmds')
}
exports.handler = function (argv) {}
6 changes: 6 additions & 0 deletions example/cmds/remote_cmds/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exports.command = 'add <name> <url>'
exports.desc = 'Add remote named <name> for repo at url <url>'
exports.builder = {}
exports.handler = function (argv) {
console.log('adding remote %s at url %s', argv.name, argv.url)
}
6 changes: 6 additions & 0 deletions example/cmds/remote_cmds/prune.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exports.command = 'prune <name> [names..]'
exports.desc = 'Delete tracked branches gone stale for remotes'
exports.builder = {}
exports.handler = function (argv) {
console.log('pruning remotes %s', [].concat(argv.name).concat(argv.names).join(', '))
}
6 changes: 6 additions & 0 deletions example/command_hierarchy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node
require('yargs')
.commandDir('cmds')
.demandCommand()
.help()
.argv

0 comments on commit fb62d88

Please sign in to comment.