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

feat: export Ux and add configAggregator to SfCommand #106

Merged
merged 7 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/exported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Flags as OclifFlags } from '@oclif/core';
export { toHelpSection, parseVarArgs } from './util';
export { Deployable, Deployer, DeployerResult } from './deployer';
export { Deauthorizer } from './deauthorizer';
export { Progress, Prompter, generateTableChoices } from './ux';
export { Progress, Prompter, generateTableChoices, Ux } from './ux';
export { SfHook } from './hooks';
export * from './types';
export { SfCommand, SfCommandInterface, StandardColors } from './sfCommand';
Expand Down
3 changes: 2 additions & 1 deletion src/flags/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export type DurationFlagConfig = {
*/
export const durationFlag = Flags.custom<Duration, DurationFlagConfig>({
parse: async (input, _, opts) => validate(input, opts),
default: async (context) => context.options.defaultValue ? toDuration(context.options.defaultValue, context.options.unit) : undefined,
default: async (context) =>
context.options.defaultValue ? toDuration(context.options.defaultValue, context.options.unit) : undefined,
});

const validate = (input: string, config: DurationFlagConfig): Duration => {
Expand Down
14 changes: 12 additions & 2 deletions src/sfCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
Mode,
EnvironmentVariable,
SfError,
ConfigAggregator,
SfdxConfigAggregator,
} from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
import * as chalk from 'chalk';
Expand Down Expand Up @@ -158,6 +160,11 @@ export abstract class SfCommand<T> extends Command {
public progress: Progress;
public project!: SfProject;

/**
* ConfigAggregator instance for accessing global and local configuration.
*/
public configAggregator!: ConfigAggregator;

private warnings: SfCommand.Warning[] = [];
private ux: Ux;
private prompter: Prompter;
Expand All @@ -166,10 +173,10 @@ export abstract class SfCommand<T> extends Command {
public constructor(argv: string[], config: Config) {
super(argv, config);
const outputEnabled = !this.jsonEnabled();
this.spinner = new Spinner(outputEnabled);
this.progress = new Progress(outputEnabled && envVars.getBoolean(EnvironmentVariable.SF_USE_PROGRESS_BAR, true));
this.ux = new Ux(outputEnabled);
this.prompter = new Prompter();
this.spinner = this.ux.spinner;
this.prompter = this.ux.prompter;
this.lifecycle = Lifecycle.getInstance();
}

Expand Down Expand Up @@ -329,6 +336,9 @@ export abstract class SfCommand<T> extends Command {
}

public async _run<R>(): Promise<R | undefined> {
this.configAggregator =
this.config.bin === 'sfdx' ? await SfdxConfigAggregator.create() : await ConfigAggregator.create();

if (this.statics.requiresProject) {
this.project = await this.assignProject();
}
Expand Down
10 changes: 10 additions & 0 deletions src/ux/ux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
import { CliUx } from '@oclif/core';
import { AnyJson } from '@salesforce/ts-types';
import { UxBase } from './base';
import { Prompter } from './prompter';
import { Spinner } from './spinner';

/**
* UX methods for plugins. Automatically suppress console output if outputEnabled is set to false.
*/
export class Ux extends UxBase {
public spinner: Spinner;
public prompter: Prompter;

public constructor(outputEnabled: boolean) {
super(outputEnabled);
this.spinner = new Spinner(outputEnabled);
this.prompter = new Prompter();
}

public table<T extends Ux.Table.Data>(data: T[], columns: Ux.Table.Columns<T>, options?: Ux.Table.Options): void {
Expand Down