Skip to content

Commit

Permalink
Use commander
Browse files Browse the repository at this point in the history
  • Loading branch information
sap1ens committed Jun 6, 2016
1 parent 265b175 commit b782d68
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 69 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ node_modules
# Optional REPL history
.node_repl_history

config.json
config.json
/lib/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/src/
3 changes: 3 additions & 0 deletions bin/syrup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

node ../lib/syrup.js "$@"
90 changes: 48 additions & 42 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
{
"name": "syrup-cli",

"version": "0.2.0",

"description": "Scrum workflow CLI for Waffle.io",

"main": "./src/syrup.js",

"repository": {
"type": "git",
"url": "https://github.com/sap1ens/syrup"
},

"bugs": {
"url": "https://github.com/sap1ens/syrup/issues"
},

"scripts": {
"list-sprints": "node_modules/babel-cli/bin/babel-node.js src/syrup.js --command list-sprints",
"new-sprint": "node_modules/babel-cli/bin/babel-node.js src/syrup.js --command new-sprint",
"clone-issue": "node_modules/babel-cli/bin/babel-node.js src/syrup.js --command clone-issue",
"help": "node_modules/babel-cli/bin/babel-node.js src/syrup.js",
"test": "echo \"Error: no test specified\" && exit 1"
},

"author": {
"name": "Yaroslav Tkachenko",
"email": "[email protected]",
"url": "http:https://sap1ens.com"
},

"license": "MIT",

"dependencies": {
"babel-cli": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"cli-table": "^0.3.1",
"github": "^0.2.4",
"nconf": "^0.8.4",
"underscore": "^1.8.3",
"yargs-parser": "^2.4.0"
}
"name": "syrup-cli",
"version": "0.2.0",
"description": "Scrum workflow CLI for Waffle.io",
"main": "./lib/syrup.js",
"bin": {
"syrup": "./bin/syrup"
},
"repository": {
"type": "git",
"url": "https://github.com/sap1ens/syrup"
},
"bugs": {
"url": "https://github.com/sap1ens/syrup/issues"
},
"scripts": {
"build": "node_modules/babel-cli/bin/babel.js src --out-dir lib",
"prepublish": "node_modules/babel-cli/bin/babel.js src --out-dir lib",
"start": "node_modules/babel-cli/bin/babel-node.js src/syrup.js",
"list-sprints": "node_modules/babel-cli/bin/babel-node.js src/syrup.js --command list-sprints",
"new-sprint": "node_modules/babel-cli/bin/babel-node.js src/syrup.js --command new-sprint",
"clone-issue": "node_modules/babel-cli/bin/babel-node.js src/syrup.js --command clone-issue",
"help": "node_modules/babel-cli/bin/babel-node.js src/syrup.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"babel": {
"presets": [
"es2015"
]
},
"author": {
"name": "Yaroslav Tkachenko",
"email": "[email protected]",
"url": "http:https://sap1ens.com"
},
"license": "MIT",
"dependencies": {
"cli-table": "^0.3.1",
"commander": "^2.9.0",
"github": "^0.2.4",
"nconf": "^0.8.4",
"underscore": "^1.8.3",
"yargs-parser": "^2.4.0"
},
"devDependencies": {
"babel-cli": "^6.9.0",
"babel-core": "^6.9.1",
"babel-preset-es2015": "^6.9.0"
}
}
55 changes: 32 additions & 23 deletions src/syrup.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
import sprints from './features/list-sprints';
import newSprint from './features/new-sprint';
import cloneIssue from './features/clone-issue';
import yargsParser from 'yargs-parser';
import program from 'commander';

const argv = yargsParser(process.argv.slice(2));

switch(argv.command) {
case 'list-sprints':
program
.command('list-sprints')
.description('list all existing Sprints')
.action(() => {
sprints();
break;
case 'new-sprint':
const nameSuffix = argv.id;
newSprint(nameSuffix);
break;
case 'clone-issue':
const repo = argv.repo;
const issueId = argv.id;
cloneIssue(repo, issueId);
break;
case 'help':
default:
console.log(`Choose the following commands:
npm run list-sprints - list all existing Sprints
npm run new-sprint -- --id $SPRINT_ID - create new Sprint using unique SPRINT_ID
npm run clone-issue -- --repo $REPO_NAME --id $ISSUE_ID - clone issue using provided repo and issue ID
npm run help`);
}
});

program
.command('new-sprint')
.description('create new Sprint using unique sprint_id')
.option('-i, --id', 'sprint ID')
.action((id) => {
newSprint(id);
});

program
.command('clone-issue')
.description('clone issue using provided repo and issue ID')
.option('-i, --id', 'issue ID')
.option('-r, --repo', 'repository name')
.action((id, repo) => {
cloneIssue(repo, id);
});

// kinda hacky, but there is no other way to replace the whole thing
program.helpInformation = () => {
return 'TODO';
};

program.parse(process.argv);

if (!program.args.length) program.help();

0 comments on commit b782d68

Please sign in to comment.