Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help command #63

Merged
merged 5 commits into from
Jun 21, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/giant-carpets-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

cli: help command
6 changes: 6 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import { promptForMissingOptions } from "./utils/prompt-for-missing-options";
import { renderIntroMessage } from "./utils/render-intro-message";
import type { Args } from "./types";
import chalk from "chalk";
import { showHelpMessage } from "./utils/show-help-message";

export async function cli(args: Args) {
try {
renderIntroMessage();
const rawOptions = await parseArgumentsIntoOptions(args);
if (rawOptions.help) {
showHelpMessage();
return;
}

const options = await promptForMissingOptions(rawOptions);
await createProject(options);
} catch (error: any) {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type ExternalExtension = {

export type RawOptions = BaseOptions & {
solidityFramework: SolidityFramework | "none" | null;
help: boolean;
};

type MergedOptions = BaseOptions & {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/parse-arguments-into-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export async function parseArgumentsIntoOptions(rawArgs: Args): Promise<RawOptio

"--extension": String,
"-e": "--extension",

"--help": Boolean,
"-h": "--help",
},
{
argv: rawArgs.slice(2).map(a => a.toLowerCase()),
Expand All @@ -60,6 +63,8 @@ export async function parseArgumentsIntoOptions(rawArgs: Args): Promise<RawOptio

const dev = args["--dev"] ?? false; // info: use false avoid asking user

const help = args["--help"] ?? false;

const project = args._[0] ?? null;

const solidityFramework = args["--solidity-framework"] ?? null;
Expand All @@ -82,6 +87,7 @@ export async function parseArgumentsIntoOptions(rawArgs: Args): Promise<RawOptio
install: hasInstallRelatedFlag ? install || !skipInstall : null,
dev,
externalExtension: extension,
help,
solidityFramework,
};
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/prompt-for-missing-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const defaultOptions: RawOptions = {
install: true,
dev: false,
externalExtension: null,
help: false,
solidityFramework: null,
};

Expand Down
14 changes: 14 additions & 0 deletions src/utils/show-help-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import chalk from "chalk";

export const showHelpMessage = () => {
console.log(` ${chalk.bold.blue("Usage:")}
${chalk.bold.green("npx create-eth<@version>")} ${chalk.gray("[-i | --install | --skip | --skip-install] [-s <solidity-framework> | --solidity-framework <solidity-framework>] [-e <extension> | --extension <extension>] [-h | --help]")}
`);
console.log(` ${chalk.bold.blue("Options:")}
${chalk.gray("-i, --install")} Install packages
${chalk.gray("--skip, --skip-install")} Skip packages installation
${chalk.gray("-s, --solidity-framework")} Choose solidity framework
${chalk.gray("-e, --extension")} Add curated or third-party extension
${chalk.gray("-h, --help")} Help
`);
};
Loading