Skip to content

Commit

Permalink
fix(options): fix regression where CLI arguments were ignored.
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed May 17, 2021
1 parent 3c0dd1c commit d1d6243
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"dependencies": {
"@types/prettier": "^2.2.3",
"chalk": "^4.1.1",
"commander": "^7.2.0",
"commander": "7.0.0",
"eslint": "^7.26.0",
"inquirer": "^8.0.0",
"json5": "^2.2.0",
Expand Down
25 changes: 2 additions & 23 deletions src/cli/command/create-command/create-command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import commander from "commander";
import {CommandAction, CommandActionOptions, CommandOptionType, CreateCommandOptions} from "./create-command-options";
import {CommandAction, CommandOptionType, CreateCommandOptions} from "./create-command-options";

/* eslint-disable @typescript-eslint/no-explicit-any */

Expand Down Expand Up @@ -35,9 +35,6 @@ function formatOptionFlags(shortHand: string | undefined, longHand: string): str

/**
* Formats the given command name, along with its arguments
*
* @param options
* @returns
*/
function formatCommandNameWithArgs<T extends CreateCommandOptions>(options: T): string {
const formattedArgs = Object.entries(options.args)
Expand Down Expand Up @@ -67,23 +64,5 @@ export function createCommand<T extends CreateCommandOptions>(options: T, action
});

// Add the action to the command
result.action((...args: unknown[]) => {
const argKeys = Object.keys(options.args);
const optionKeys = Object.keys(options.options);
const actionOptions = {} as CommandActionOptions<T>;
for (let i = 0; i < args.length; i++) {
if (argKeys[i] == null) continue;
actionOptions[argKeys[i] as keyof typeof actionOptions] = args[i] as any;
}

// Take the last argument
const lastArg = args[args.length - 1];
// Apply all option values
for (const key of optionKeys) {
actionOptions[key as keyof typeof actionOptions] = (lastArg as any)[key];
}

// Invoke the action
action(actionOptions);
});
result.action(action);
}
2 changes: 1 addition & 1 deletion src/readme/generate-readme/generate-readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ async function generateInstallSection(context: GenerateReadmeContext): Promise<v
`### Run once with npx\n\n` +
"```\n" +
`$ npx${peerDependencies.length === 0 ? "" : peerDependencies.map(peerDependency => ` -p ${peerDependency}`).join("")}${
firstBinName === context.pkg.name ? ` ${context.pkg.name}` : ` -p ${context.pkg.name} ${firstBinName}`
firstBinName === context.pkg.name && peerDependencies.length === 0 ? ` ${context.pkg.name}` : ` -p ${context.pkg.name} ${firstBinName}`
}\n` +
"```") +
(peerDependencies.length < 1
Expand Down

0 comments on commit d1d6243

Please sign in to comment.