Skip to content

Commit 3bf719b

Browse files
authored
Add --force option to init CLI command (#775)
This PR adds a `--force` option to the `codama init` command that allows us to override existing configuration files.
1 parent 7e36ab1 commit 3bf719b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/cli/src/commands/init.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,24 @@ export function setInitCommand(program: Command): void {
2121
.command('init')
2222
.argument('[output]', 'Optional path used to output the configuration file')
2323
.option('-d, --default', 'Bypass prompts and select all defaults options')
24+
.option('--force', 'Overwrite existing configuration file, if any')
2425
.option('--js', 'Forces the output to be a JavaScript file')
2526
.option('--gill', 'Forces the output to be a gill based JavaScript file')
2627
.action(doInit);
2728
}
2829

2930
type InitOptions = {
3031
default?: boolean;
31-
js?: boolean;
32+
force?: boolean;
3233
gill?: boolean;
34+
js?: boolean;
3335
};
3436

3537
async function doInit(explicitOutput: string | undefined, options: InitOptions) {
3638
const output = getOutputPath(explicitOutput, options);
3739
const configFileType = getConfigFileType(output, options);
3840

39-
if (await canRead(output)) {
41+
if (!options.force && (await canRead(output))) {
4042
throw new CliError(`Configuration file already exists.`, [`${pico.bold('Path')}: ${output}`]);
4143
}
4244

0 commit comments

Comments
 (0)