Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delta Control Mapping for Distinct Profiles #2805

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ out
**/saf-cli.log
*.html
saf-cli.log
*.log
9 changes: 9 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"flat": "^6.0.1",
"form-data": "^4.0.0",
"fs-extra": "^11.1.1",
"fuse.js": "^7.0.0",
"get-installed-path": "^4.0.8",
"htmlparser2": "^9.0.0",
"https": "^1.0.0",
Expand Down
60 changes: 60 additions & 0 deletions src/baseCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {Command, Flags, Interfaces} from '@oclif/core'

export type Flags<T extends typeof Command> = Interfaces.InferredFlags<typeof BaseCommand['baseFlags'] & T['flags']>
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>

export abstract class InteractiveBaseCommand extends Command {
static readonly baseFlags = {
interactive: Flags.boolean({
aliases: ['interactive', 'ask-me'],
// Show this flag under a separate GLOBAL section in help.
helpGroup: 'GLOBAL',
description: 'Collect input tags interactively - not available for all CLI commands',
}),
};
}

export abstract class BaseCommand<T extends typeof Command> extends Command {
// define flags that can be inherited by any command that extends BaseCommand
static readonly baseFlags = {
...InteractiveBaseCommand.baseFlags,
logLevel: Flags.option({
char: 'L',
default: 'info',
helpGroup: 'GLOBAL',
options: ['info', 'warn', 'debug', 'verbose'] as const,
description: 'Specify level for logging.',
})(),
}

protected flags!: Flags<T>
protected args!: Args<T>

public async init(): Promise<void> {
await super.init()
const {args, flags} = await this.parse({
flags: this.ctor.flags,
baseFlags: (super.ctor as typeof BaseCommand).baseFlags,
enableJsonFlag: this.ctor.enableJsonFlag,
args: this.ctor.args,
strict: this.ctor.strict,
})
this.flags = flags as Flags<T>
this.args = args as Args<T>
}

protected async catch(err: Error & {exitCode?: number}): Promise<any> { // skipcq: JS-0116
// If error message is for missing flags, display what fields
// are required, otherwise show the error
if (err.message.includes('See more help with --help')) {
this.warn(err.message)
} else {
this.warn(err)
}
}

protected async finally(_: Error | undefined): Promise<any> { // skipcq: JS-0116
// called after run and catch regardless of whether or not the command errored
return super.finally(_)
}
}
Loading
Loading