-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweaks to how command execution results in explorer view updates
- Loading branch information
1 parent
adf125c
commit 1e4f1b3
Showing
7 changed files
with
167 additions
and
20 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/extension/commands/heroku-cli/heroku-addon-command-runner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { AddOn } from '@heroku-cli/schema'; | ||
import { CommandMeta } from '../../manifest'; | ||
import { herokuCommand, HerokuOutputChannel } from '../../meta/command'; | ||
import { HerokuCommandRunner } from './heroku-command-runner'; | ||
|
||
@herokuCommand({ outputChannelId: HerokuOutputChannel.CommandOutput }) | ||
/** | ||
* Any other commands. This acts as a catch-all for commands | ||
* that do to have a dedicated command runner. | ||
*/ | ||
export class HerokuAddOnCommandRunner extends HerokuCommandRunner<unknown> { | ||
public static COMMAND_ID = 'heroku:addOn:runner'; | ||
|
||
/** | ||
* | ||
* @inheritdoc | ||
*/ | ||
protected hydrateArgs( | ||
userInputByArg: Map<string, string | undefined>, | ||
args: CommandMeta['args'], | ||
addOn: AddOn | ||
): PromiseLike<void> | void { | ||
if (args.app?.required && addOn) { | ||
userInputByArg.set('app', addOn.app.name); | ||
} | ||
if (args.addon?.required && addOn) { | ||
userInputByArg.set('addon', addOn.name); | ||
} | ||
if (args.addonName?.required && addOn) { | ||
userInputByArg.set('addonName', addOn.name); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @inheritdoc | ||
*/ | ||
protected hydrateFlags( | ||
userInputByFlag: Map<string, string | undefined>, | ||
flags: CommandMeta['flags'], | ||
addOn: AddOn | ||
): PromiseLike<void> | void { | ||
if (flags.app && addOn) { | ||
userInputByFlag.set('app', addOn.app.name); | ||
} | ||
if (flags.addon?.required && addOn) { | ||
userInputByFlag.set('addon', addOn.name); | ||
} | ||
if (flags.addonName?.required && addOn) { | ||
userInputByFlag.set('addonName', addOn.name); | ||
} | ||
// Special case for destructive actions e.g. ones with a `confirm` prompt | ||
if (flags.confirm) { | ||
Reflect.set(flags.confirm, 'required', true); | ||
Reflect.set(flags.confirm, 'type', 'boolean'); | ||
Reflect.set(flags.confirm, 'default', true); | ||
Reflect.set(flags.confirm, 'hidden', false); | ||
Reflect.set(flags.confirm, 'default', addOn?.app?.name); | ||
if (!flags.confirm.description) { | ||
Reflect.set(flags.confirm, 'description', 'this is a destructive action which cannot be undone'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 22 additions & 5 deletions
27
src/extension/commands/heroku-cli/heroku-unknown-command-runner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
import { CommandMeta } from '../../manifest'; | ||
import { herokuCommand, HerokuOutputChannel } from '../../meta/command'; | ||
import { HerokuCommandRunner } from './heroku-command-runner'; | ||
|
||
@herokuCommand({ outputChannelId: HerokuOutputChannel.CommandOutput }) | ||
/** | ||
* Any other commands. | ||
* Any other commands. This acts as a catch-all for commands | ||
* that do to have a dedicated command runner. | ||
*/ | ||
export class HerokuUnknownCommandRunner extends HerokuCommandRunner<unknown> { | ||
public static COMMAND_ID = 'heroku:unknown:runner'; | ||
/** | ||
* | ||
* @inheritdoc | ||
*/ | ||
protected hydrateFlags(): PromiseLike<void> | void { | ||
// noop | ||
protected hydrateArgs( | ||
userInputByArg: Map<string, string | undefined>, | ||
args: CommandMeta['args'], | ||
unknownData?: { app?: { id: string; name: string }; id?: string; name?: string } | ||
): PromiseLike<void> | void { | ||
if (args.app?.required && unknownData) { | ||
userInputByArg.set('app', unknownData.name ?? unknownData.app?.name); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @inheritdoc | ||
*/ | ||
protected hydrateArgs(): PromiseLike<void> | void { | ||
// noop | ||
protected hydrateFlags( | ||
userInputByFlag: Map<string, string | undefined>, | ||
flags: CommandMeta['flags'], | ||
unknownData?: { app?: { id: string; name: string }; id?: string; name?: string } | ||
): PromiseLike<void> | void { | ||
if (flags.app?.required && unknownData) { | ||
userInputByFlag.set('app', unknownData.name ?? unknownData.app?.name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters