Skip to content

Commit

Permalink
feat(main): initial cut
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 1, 2019
1 parent 041a714 commit ebde410
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 15 deletions.
17 changes: 17 additions & 0 deletions bin/agoric
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const path = require('path');

esmRequire = require('esm')(module);
const main = esmRequire('../lib/main.js').default;
const progname = process.argv[1];

process.on('SIGINT', () => process.exit(-1));

main(path.basename(process.argv[1]), process.argv.splice(2)).then(
res => res === undefined || process.exit(res),
rej => {
console.error(`${progname}: error:`, rej);
process.exit(1);
},
);
47 changes: 47 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import chalk from 'chalk';
import parseArgs from 'minimist';

const VERSION = 'Agoric 0.1.0';

const main = async (progname, rawArgs) => {
const { _: args, ...opts } = parseArgs(rawArgs, {
boolean: ['version', 'help'],
stopEarly: true,
});

const usage = status => {
if (status) {
console.error(`Type '${progname} --help' for more information.`);
return status;
}
console.log(`\
Usage: ${progname} [command] [...args]
help display this help and exit
`);
return 0;
};

if (opts.version) {
console.log(VERSION);
return 0;
}

if (opts.help) {
return usage(0);
}

const cmd = args[0];
switch (cmd) {
case undefined:
console.error(`${progname}: error: you must specify a COMMAND`);
return usage(1);
case 'help':
return usage(0);
default:
console.error(`${progname}: error: unrecognized COMMAND ${cmd}`);
return usage(1);
}
};

export default main;
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"tape-promise": "^4.0.0"
},
"dependencies": {
"esm": "^3.2.5"
"chalk": "^2.4.2",
"esm": "^3.2.5",
"minimist": "^1.2.0"
},
"keywords": [],
"files": [
Expand Down

0 comments on commit ebde410

Please sign in to comment.