Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Ensure proper usage of yargs + npm create script with using -- #705

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
12 changes: 11 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,19 @@ Runs all tests:

- `npm test` (or the shorthand, `npm t`)

## To create a new chain/flavor

- `npm run create -- <name> --location chains`

**NOTE:** The `--` between `npm run create` and `<name>` is required to properly use this script.

This will create a new folder at `src/chains/<name>` where `<name>` should be the flavor name (e.g. `ethereum`), which you then can [create packages under](#to-create-a-new-package).

## To create a new package

- `npm run create <name> --location <location> [--folder <folder>]`
- `npm run create -- <name> --location <location> [--folder <folder>]`

**NOTE:** The `--` between `npm run create` and `<name>` is required to properly use this script.

This will create a new package with Ganache defaults at `src/<location>/<name>`.

Expand Down
11 changes: 6 additions & 5 deletions scripts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const chainLocations = getDirectories(join(__dirname, "../src/chains")).map(
locations = locations.concat(chainLocations);
const argv = yargs
.command(
`$0 <name> --location [--folder]`,
`$0 <name> [options]`,
`Create a new package in the given location with the provided name.`,
yargs => {
return yargs
Expand All @@ -40,28 +40,29 @@ const argv = yargs
chalk`{bold Usage}\n {bold $} {dim <}name{dim >} {dim --}location {dim <}location{dim >} {dim [--folder <folder>]}`
)
.positional("name", {
describe: ` The name for the new package.`,
describe: `The name for the new package.`,
type: "string",
demandOption: true
})
.option("location", {
alias: "l",
describe: `The location for the new package.`,
type: "string",
choices: locations,
demandOption: true
})
.option("folder", {
alias: "f",
describe: chalk`Optional override for the folder name for the package instead of using {dim <}name{dim >}.`
describe: chalk`Optional override for the folder name for the package instead of using {dim <}name{dim >}.`,
type: "string",
demandOption: false
});
}
)
.demandCommand()
.version(false)
.help(false)
.updateStrings({
"Positionals:": chalk.bold("Options"),
"Options:": ` `,
Comment on lines -63 to -64
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why you insisted on joining these two while still having positional and non-positional arguments (from the way the script was written, despite they were all being processed as positional anyways). Regardless, if you have two separate types of arguments, they should be separated to help out developers understand what is what. By joining these, you're removing contextual help/usage information for a little extra screen space. I encourage you keep this if you choose this PR option.

"Not enough non-option arguments: got %s, need at least %s": {
one: chalk`{red {bold ERROR! Not enough non-option arguments:}\n got %s, need at least %s}`,
other: chalk`{red {bold ERROR! Not enough non-option arguments:}\n got %s, need at least %s}`
Expand Down