Skip to content

Commit

Permalink
Merge pull request #170 from Tajnymag/master
Browse files Browse the repository at this point in the history
Migrated to the new argparse v2 syntax

Fixes #168
  • Loading branch information
luisfpg authored Sep 8, 2021
2 parents 4d3c507 + 072e3cb commit c2a4703
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
22 changes: 15 additions & 7 deletions lib/cmd-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const DefaultConfig = 'ng-openapi-gen.json';

function createParser() {
const argParser = new ArgumentParser({
version: pkg.version,
addHelp: true,
add_help: true,
description: `
Generator for API clients described with OpenAPI 3.0 specification for
Angular 6+ projects. Requires a configuration file, which defaults to
Expand All @@ -25,14 +24,23 @@ argument could be set as '--service-suffix Suffix'
As the only required argument is the input for OpenAPI specification,
a configuration file is only required if no --input argument is set.`.trim()
});
argParser.addArgument(
['-c', '--config'],
argParser.add_argument(
'-v',
'--version',
{
action: 'version',
version: pkg.version
}
);
argParser.add_argument(
'-c',
'--config',
{
help: `
The configuration file to be used. If not specified, assumes that
${DefaultConfig} in the current directory`.trim(),
dest: 'config',
defaultValue: `./${DefaultConfig}`
default: `./${DefaultConfig}`
}
);
const props = schema.properties;
Expand All @@ -51,7 +59,7 @@ ${DefaultConfig} in the current directory`.trim(),
if (kebab !== key) {
names.push('--' + kebab);
}
argParser.addArgument(names, {
argParser.add_argument(...(names as [string]), {
help: desc.description,
dest: key
});
Expand All @@ -64,7 +72,7 @@ ${DefaultConfig} in the current directory`.trim(),
*/
export function parseOptions(sysArgs?: string[]): Options {
const argParser = createParser();
const args = argParser.parseArgs(sysArgs);
const args = argParser.parse_args(sysArgs);
let options: any = {};
if (args.config) {
if (fs.existsSync(args.config)) {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@loopback/openapi-v3-types": "^1.2.1",
"@types/argparse": "^1.0.38",
"@types/argparse": "^2.0.10",
"@types/fs-extra": "^9.0.8",
"@types/jsesc": "^2.5.1",
"@types/json-schema": "^7.0.7",
Expand Down

0 comments on commit c2a4703

Please sign in to comment.