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 all commits
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 @@ -81,7 +81,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
26 changes: 26 additions & 0 deletions src/bin/phenomic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "babel-polyfill"
import { join } from "path"
import colors from "chalk"

import setup from "./commands/setup/index.js"

Expand Down Expand Up @@ -68,4 +69,29 @@ yargs.command(
runner
)

yargs.check((argv) => {
// requires at least 1 argument
// show help when type `$ phenomic`
// argv._ = [
// nodePath,
// pathToPhenomicScript,
// input argvs
// ]
Copy link
Owner

Choose a reason for hiding this comment

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

Can you remove this commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I added this on purpose to explain about argv._.length < 3

if (argv._.length < 3) {
throw new Error(
colors.bgRed(colors.white("ERROR")) +
colors.red(" You must specify command for Phenomic CLI")
)
}

// Unknown command
const currentCommand = argv._[2]
if ([ "start", "build", "setup" ].indexOf(currentCommand) < 0) {
throw new Error(
colors.bgRed(colors.white("ERROR")) +
Copy link
Owner

Choose a reason for hiding this comment

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

We should probably try to output a more fancy error prefix than "ERROR" :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MoOx what are you suggesting?

colors.red(` Unknown command "${ currentCommand }"`)
)
}
})

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

yargs
.version(() => version)
.help()
.usage("Usage: phenomic <command> [options]")
// .hep()
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.

Copy link
Owner

Choose a reason for hiding this comment

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

oups :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops :D

.showHelpOnFail()
.epilogue(
"For more information about the configuration, " +
Expand All @@ -32,13 +33,6 @@ Object.keys(definitions).forEach((optName) => {
if (option.description) {
yargs.describe(optName, option.description)
}

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

export default yargs