Skip to content

Commit

Permalink
refactor: remove workingDirectory argument
Browse files Browse the repository at this point in the history
BREAKING CHANGE: removing the `workingDirectory` argument from the `openapi` family of commands
  • Loading branch information
kanadgupta committed Sep 15, 2023
1 parent d423b4c commit 742f3af
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 56 deletions.
10 changes: 1 addition & 9 deletions src/cmds/openapi/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { validateFilePath } from '../../lib/validatePromptInput.js';
interface Options {
out?: string;
spec?: string;
workingDirectory?: string;
}

export default class OpenAPIConvertCommand extends Command {
Expand All @@ -39,20 +38,13 @@ export default class OpenAPIConvertCommand extends Command {
type: String,
description: 'Output file path to write converted file to',
},
this.getWorkingDirArg(),
];
}

async run(opts: ZeroAuthCommandOptions<Options>) {
await super.run(opts);

const { spec, workingDirectory } = opts;

if (workingDirectory) {
const previousWorkingDirectory = process.cwd();
process.chdir(workingDirectory);
Command.debug(`switching working directory from ${previousWorkingDirectory} to ${process.cwd()}`);
}
const { spec } = opts;

const { preparedSpec, specPath, specType } = await prepareOas(spec, 'openapi:convert', { convertToLatest: true });
const parsedPreparedSpec: OASDocument = JSON.parse(preparedSpec);
Expand Down
10 changes: 1 addition & 9 deletions src/cmds/openapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interface Options {
update?: boolean;
useSpecVersion?: boolean;
version?: string;
workingDirectory?: string;
}

export default class OpenAPICommand extends Command {
Expand All @@ -54,7 +53,6 @@ export default class OpenAPICommand extends Command {
type: String,
defaultOption: true,
},
this.getWorkingDirArg(),
{
name: 'useSpecVersion',
type: Boolean,
Expand Down Expand Up @@ -90,7 +88,7 @@ export default class OpenAPICommand extends Command {
async run(opts: AuthenticatedCommandOptions<Options>) {
await super.run(opts);

const { dryRun, key, id, spec, create, raw, title, useSpecVersion, version, workingDirectory, update } = opts;
const { dryRun, key, id, spec, create, raw, title, useSpecVersion, version, update } = opts;

let selectedVersion = version;
let isUpdate: boolean;
Expand All @@ -111,12 +109,6 @@ export default class OpenAPICommand extends Command {
);
}

if (workingDirectory) {
const previousWorkingDirectory = process.cwd();
process.chdir(workingDirectory);
Command.debug(`switching working directory from ${previousWorkingDirectory} to ${process.cwd()}`);
}

if (version && id) {
Command.warn(
"We'll be using the version associated with the `--id` option, so the `--version` option will be ignored.",
Expand Down
10 changes: 1 addition & 9 deletions src/cmds/openapi/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import SoftError from '../../lib/softError.js';
interface Options {
feature?: string[];
spec?: string;
workingDirectory?: string;
}

export default class OpenAPIInspectCommand extends Command {
Expand All @@ -40,7 +39,6 @@ export default class OpenAPIInspectCommand extends Command {
type: String,
defaultOption: true,
},
this.getWorkingDirArg(),
{
name: 'feature',
type: String,
Expand Down Expand Up @@ -218,7 +216,7 @@ export default class OpenAPIInspectCommand extends Command {
async run(opts: ZeroAuthCommandOptions<Options>) {
await super.run(opts);

const { spec, workingDirectory, feature: features } = opts;
const { spec, feature: features } = opts;

// If we have features we should validate that they're supported.
if (features?.length) {
Expand All @@ -232,12 +230,6 @@ export default class OpenAPIInspectCommand extends Command {
}
}

if (workingDirectory) {
const previousWorkingDirectory = process.cwd();
process.chdir(workingDirectory);
Command.debug(`switching working directory from ${previousWorkingDirectory} to ${process.cwd()}`);
}

const { preparedSpec, definitionVersion } = await prepareOas(spec, 'openapi:inspect', { convertToLatest: true });
this.definitionVersion = definitionVersion.version;
const parsedPreparedSpec: OASDocument = JSON.parse(preparedSpec);
Expand Down
10 changes: 1 addition & 9 deletions src/cmds/openapi/reduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface Options {
spec?: string;
tag?: string[];
title?: string;
workingDirectory?: string;
}

export default class OpenAPIReduceCommand extends Command {
Expand Down Expand Up @@ -66,20 +65,13 @@ export default class OpenAPIReduceCommand extends Command {
description: 'Output file path to write reduced file to',
},
this.getTitleArg(),
this.getWorkingDirArg(),
];
}

async run(opts: ZeroAuthCommandOptions<Options>) {
await super.run(opts);

const { spec, title, workingDirectory } = opts;

if (workingDirectory) {
const previousWorkingDirectory = process.cwd();
process.chdir(workingDirectory);
Command.debug(`switching working directory from ${previousWorkingDirectory} to ${process.cwd()}`);
}
const { spec, title } = opts;

const { preparedSpec, specPath, specType } = await prepareOas(spec, 'openapi:reduce', { title });
const parsedPreparedSpec: OASDocument = JSON.parse(preparedSpec);
Expand Down
10 changes: 1 addition & 9 deletions src/cmds/openapi/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import prepareOas from '../../lib/prepareOas.js';

export interface Options {
spec?: string;
workingDirectory?: string;
}

export default class OpenAPIValidateCommand extends Command {
Expand All @@ -27,21 +26,14 @@ export default class OpenAPIValidateCommand extends Command {
type: String,
defaultOption: true,
},
this.getWorkingDirArg(),
this.getGitHubArg(),
];
}

async run(opts: ZeroAuthCommandOptions<Options>) {
await super.run(opts);

const { spec, workingDirectory } = opts;

if (workingDirectory) {
const previousWorkingDirectory = process.cwd();
process.chdir(workingDirectory);
Command.debug(`switching working directory from ${previousWorkingDirectory} to ${process.cwd()}`);
}
const { spec } = opts;

const { specPath, specType } = await prepareOas(spec, 'openapi:validate');
return Promise.resolve(chalk.green(`${specPath} is a valid ${specType} API definition!`)).then(msg =>
Expand Down
11 changes: 0 additions & 11 deletions src/lib/baseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,6 @@ export default class Command {
];
}

/**
* Used in the `openapi` family of commands where `workingDirectory` is an option.
*/
getWorkingDirArg(): OptionDefinition {
return {
name: 'workingDirectory',
type: String,
description: 'Working directory (for usage with relative external references)',
};
}

static debug(msg: string) {
debug(msg);
}
Expand Down

0 comments on commit 742f3af

Please sign in to comment.