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

Commit

Permalink
Fix issues with yargs configuration. Remove duplicate 'instances' com…
Browse files Browse the repository at this point in the history
…mand definition. Don't show '--flavor' option on 'instances' command. Move '--detach' option out of 'Server' group
  • Loading branch information
jeffsmale90 committed Jul 27, 2023
1 parent b42258c commit 809891c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 64 deletions.
35 changes: 2 additions & 33 deletions src/packages/cli/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import yargs from "yargs";
import { StartArgs, GanacheArgs } from "./types";
import chalk from "chalk";
import { EOL } from "os";
import { configureFlavorOptions, loadFlavorFromArgs } from "./flavors";
import { configureStartCommandForFlavor, loadFlavorFromArgs } from "./flavors";
import { center, highlight, wrapWidth } from "./helpers";

const NEED_HELP = "Need more help? Reach out to the Truffle community at";
Expand Down Expand Up @@ -47,38 +47,7 @@ export const parseArgs = (version: string, rawArgs = process.argv.slice(2)) => {
);

const { flavor, options: flavorOptions } = loadFlavorFromArgs(rawArgs);
configureFlavorOptions(yargs, flavor, flavorOptions);

yargs.command(
"instances",
highlight(
"Manage instances of Ganache running in detached mode." +
EOL +
"(Ganache can be run in detached mode by providing the `--detach` flag)"
),
_yargs => {
_yargs
.command(
"list",
"List instances running in detached mode",
_ => {},
listArgs => {
listArgs.action = "list";
}
)
.command(
"stop <name>",
"Stop the instance specified by <name>",
stopArgs => {
stopArgs.positional("name", { type: "string" });
},
stopArgs => {
stopArgs.action = "stop";
}
)
.version(false);
}
);
configureStartCommandForFlavor(yargs, flavor, flavorOptions);

yargs
.command(
Expand Down
28 changes: 13 additions & 15 deletions src/packages/cli/src/flavors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ function addFlavorFlag(yargs: Argv<{}>) {
});
}

function addOptions(
function addDetachFlag(yargs: Argv<{}>) {
yargs.option("detach", {
type: "boolean",
description: `Run Ganache in detached (daemon) mode.
See \`ganache instances --help\` for information on managing detached instances.`,
alias: ["D", "😈"]
});
}

export function configureStartCommandForFlavor(
yargs: Argv<{}>,
flavor: string,
options: {
Expand Down Expand Up @@ -70,21 +79,10 @@ function addOptions(

applyDefaults(combinedCliOptions, args);
applyDefaults(combinedServerOptions, args);

addFlavorFlag(args);
addDetachFlag(args);
},
parsed => (parsed.action = parsed.detach ? "start-detached" : "start")
);
}

export function configureFlavorOptions(
yargs: Argv<{}>,
flavor: string,
options: {
provider?: OptionsConfig<any>;
server?: OptionsConfig<any>;
cli?: OptionsConfig<any>;
}
) {
addFlavorFlag(yargs);

addOptions(yargs, flavor, options);
}
6 changes: 6 additions & 0 deletions src/packages/cli/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ function addOption(

const key = `${category}.${option}`;

// todo: this is a terrible hack - the `default` property must be set for `server.host` and
// `server.port` in order for detach mode to work
if ((key === "server.host" || key === "server.port") && optionObj.default) {
options.default = optionObj.default(state);
}

// First, create *hidden* deprecated aliases...
argv = addAliases(argv, legacyAliases, key);

Expand Down
9 changes: 0 additions & 9 deletions src/packages/flavor/src/options/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,5 @@ export type CliConfig = {
host: boolean;
};
};

/**
* Host for the server to bind to
*
* @defaultValue true
*/
readonly detach: {
type: boolean;
};
};
};
7 changes: 0 additions & 7 deletions src/packages/flavor/src/options/cli/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,5 @@ export const CliOptions: CliOptions = {
legacyName: "host",
cliType: "string",
cliAliases: ["h", "host"]
},
detach: {
normalize: detach => detach,
cliDescription: `Run Ganache in detached (daemon) mode.
See \`ganache instances --help\` for information on managing detached instances.`,
cliType: "boolean",
cliAliases: ["D", "😈", "detach"]
}
};

0 comments on commit 809891c

Please sign in to comment.