Skip to content

Commit

Permalink
feat: basic help message
Browse files Browse the repository at this point in the history
  • Loading branch information
rin-st committed Jun 19, 2024
1 parent 99f6005 commit 84bcf94
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
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 @@ -8,6 +8,7 @@ export type RawOptions = {
dev: boolean;
extensions: Extension[] | null;
externalExtension: ExternalExtension | null;
help: boolean;
};

export type ExternalExtension = {
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 @@ -41,6 +41,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 @@ -53,6 +56,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;

// ToDo. Allow multiple
Expand All @@ -75,5 +80,6 @@ export async function parseArgumentsIntoOptions(rawArgs: Args): Promise<RawOptio
dev,
extensions: null, // TODO add extensions flags
externalExtension: extension,
help,
};
}
2 changes: 2 additions & 0 deletions src/utils/prompt-for-missing-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const defaultOptions: RawOptions = {
dev: false,
extensions: [],
externalExtension: null,
help: false,
};

const invalidQuestionNames = ["project", "install"];
Expand Down Expand Up @@ -69,6 +70,7 @@ export async function promptForMissingOptions(options: RawOptions): Promise<Opti
dev: options.dev ?? defaultOptions.dev,
extensions: [],
externalExtension: options.externalExtension,
help: options.help,
};

config.questions.forEach(question => {
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 | -s | --skip | --skip-install] [-e <extension> | --extension <extension>] [--dev] [-h | --help]")}
`);
console.log(` ${chalk.bold.blue("Options:")}
${chalk.gray("-i, --install")} Install packages
${chalk.gray("-s, --skip, --skip-install")} Skip packages installation
${chalk.gray("-e, --extension")} Add curated or third-party extension
${chalk.gray("--dev")} Developer mode
${chalk.gray("-h, --help")} Help
`);
};

0 comments on commit 84bcf94

Please sign in to comment.