Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Add help for $ phenomic and unknown commands #757

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"webpack-dev-middleware": "^1.6.1",
"webpack-hot-middleware": "^2.12.2",
"webpack-notifier": "^1.4.0",
"yargs": "^4.3.1"
"yargs": "^5.0.0"
},
"devDependencies": {
"ava": "^0.16.0",
Expand Down
22 changes: 21 additions & 1 deletion src/bin/phenomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,24 @@ yargs.command(
runner
)

yargs.parse(process.argv)
const argv = yargs.argv

checkCommands(yargs, argv, 1)

function checkCommands(yargs, argv, numRequired) {
if (argv._.length < numRequired) {
yargs
.showHelp()
}
else {
const currentCommand = argv._[0]

if ([ "start", "build", "setup" ].indexOf(currentCommand) < 0) {
console.log(`Unknown command "${ currentCommand }"`)
console.log()
yargs.showHelp()
}
}
}

// yargs.parse(process.argv)
8 changes: 4 additions & 4 deletions src/configurator/yargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import definitions from "./definitions.js"

yargs
.version(() => version)
.usage("Usage: phenomic <command> [options]")
.help()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this thing not working?

Copy link
Contributor Author

@thangngoc89 thangngoc89 Sep 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not working at all since we don't any validations with yargs.check(). But this is actually an interesting idea. I could move the validation part to yarts.check() and let yargs its jobs.

.showHelpOnFail()
.epilogue(
"For more information about the configuration, " +
"https://phenomic.io/"
Expand Down Expand Up @@ -35,9 +35,9 @@ Object.keys(definitions).forEach((optName) => {

// made by hand for now, we might revisit option this later
// if (validators[optName]) {
// yargs.check(() => {
//
// })
// yargs.check((...args) => {
//
// })
// }
})

Expand Down