Skip to content

Commit bbca56f

Browse files
committed
🐛 Fixes broken sub command options by making the default command a subcommand
1 parent 7f1e99c commit bbca56f

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

‎.changeset/gentle-fans-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codeshift/cli': patch
3+
---
4+
5+
Fixes a bug where consistent option names used across default and subcommands were breaking.

‎packages/cli/src/index.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import { Command, Option } from 'commander';
1515
const program = new Command();
1616

1717
program
18+
.command(`${packageJson.name} [path...]`, { isDefault: true })
1819
.version(packageJson.version, '-v, --version')
19-
.name(packageJson.name)
2020
.usage('[global options] <file-paths>...')
2121
.option(
22-
'-t,--transform <value>',
22+
'-t, --transform <value>',
2323
'The transform to run, will prompt for a transform if not provided and no module is passed',
2424
)
2525
.option(
@@ -60,7 +60,7 @@ Examples:
6060
# Run the "my-custom-transform" transform
6161
$ codeshift-cli -t path/to/my-custom-transform /project/src`,
6262
)
63-
.action((options, command) => main(command.args, options));
63+
.action((path, options) => main(path, options));
6464

6565
program
6666
.command('list <package-names...>')
@@ -69,22 +69,28 @@ program
6969

7070
program
7171
.command('init [path]')
72-
.description('create a new codemod package')
73-
// FIXME: Commander seems to have issues parsing the paths and arguments
74-
.option('--package-name <name>', 'Name of the package')
75-
.option('--version <version>', 'Target version')
76-
.action((path, options) => init(options.packageName, options.version, path))
72+
.description('creates a new codeshift package')
73+
.requiredOption('--package-name <value>', 'Name of the package')
74+
.option('-t, --transform <value>', 'Transform version')
75+
.option('-p, --preset <value>', 'Preset transfrom')
76+
.action((path, options) =>
77+
init(options.packageName, options.transform, options.preset, path),
78+
)
7779
.addHelpText(
7880
'after',
7981
`
8082
Examples:
81-
$ codeshift-cli init --package-name foobar --version 10.0.0 ~/Desktop
83+
# Initializes a new codeshift package with a transform for 10.0.0
84+
$ codeshift-cli init --package-name foobar --transform 10.0.0 ~/Desktop
85+
86+
# Initializes a new codeshift package with a preset "update-imports"
87+
$ codeshift-cli init --package-name foobar --preset update-imports ~/Desktop
8288
`,
8389
);
8490

8591
program
8692
.command('validate [path]')
87-
.description('validates if a codemod package is publishable')
93+
.description('validates if a codeshift package is publishable')
8894
.action(path => validate(path))
8995
.addHelpText(
9096
'after',

0 commit comments

Comments
 (0)