Skip to content

Commit

Permalink
refactor: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Lodin committed Feb 28, 2025
1 parent baa6ac0 commit 046694a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ private void applyPlugins(GeneratorConfiguration.@NonNull Plugins plugins) {

private void prepareOpenAPI(ArrayList<Object> arguments) {
logger.debug("Using OpenAPI file: {}", openAPIFile);
arguments.add("-i");
arguments.add(openAPIFile);
}

Expand Down
16 changes: 10 additions & 6 deletions packages/ts/generator-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import type { PackageJson } from 'type-fest';
import GeneratorIO from './GeneratorIO.js';

const {
values: { inputFile, help, outputDir, plugin: plugins, verbose, version },
positionals: [file],
values: { help, outputDir, plugin: plugins, verbose, version },
} = parseArgs({
options: {
inputFile: {
Expand Down Expand Up @@ -37,15 +38,18 @@ const {
type: 'boolean',
},
},
allowPositionals: true,
});

if (help) {
// eslint-disable-next-line no-console
console.log(`Usage:
tsgen
tsgen <file> [OPTIONS]
Arguments:
file OpenAPI JSON schema file (required)
Options:
-i, --input-file OpenAPI schema file (required)
-h, --help Show this screen
-o, --output-dir Output directory
-p, --plugin <path> Use the plugin loadable by <path>.
Expand All @@ -57,8 +61,8 @@ Options:
// eslint-disable-next-line no-console
console.log(packageJson.version);
} else {
if (!inputFile) {
throw new Error('Input file is required');
if (!file) {
throw new Error('OpenAPI file is required');
}

const logger = new LoggerFactory({ verbose });
Expand All @@ -75,7 +79,7 @@ Options:
);
const generator = new Generator(resolvedPlugins, { logger, outputDir });

const files = await generator.process(await readFile(inputFile, 'utf8'));
const files = await generator.process(await readFile(file, 'utf8'));
const filesToDelete = await io.getExistingGeneratedFiles();
const generatedFiles = await io.writeGeneratedFiles(files);

Expand Down
2 changes: 1 addition & 1 deletion packages/ts/generator-cli/test/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ describe('cli', () => {
});

it('should throw an error if input file is not provided', async () => {
await expect(execAsync(`npx tsx src/index.ts`)).rejects.and.throws(Error, 'Input file is required');
await expect(execAsync(`npx tsx src/index.ts`)).rejects.and.throws(Error, 'OpenAPI file is required');
});
});
6 changes: 4 additions & 2 deletions packages/ts/generator-cli/test/fixtures/help.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Usage:
tsgen
tsgen <file> [OPTIONS]

Arguments:
file OpenAPI JSON schema file (required)

Options:
-i, --input-file OpenAPI schema file (required)
-h, --help Show this screen
-o, --output-dir Output directory
-p, --plugin <path> Use the plugin loadable by <path>.
Expand Down

0 comments on commit 046694a

Please sign in to comment.