Skip to content

Commit

Permalink
Merge pull request #477 from salesforcecli/ts/W-13992563
Browse files Browse the repository at this point in the history
feat: Adds verbose option to package convert
  • Loading branch information
shetzel authored Oct 31, 2023
2 parents 4ae65e3 + 337f8ff commit 5aa8372
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
1 change: 1 addition & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"package",
"seed-metadata",
"target-dev-hub",
"verbose",
"wait"
],
"alias": ["force:package:convert"],
Expand Down
4 changes: 4 additions & 0 deletions messages/package_convert.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Minutes to wait for the package version to be created.

Instance where the conversion package version will be created, such as NA50.

# flags.verbose.summary

Display verbose command output.

# in-progress

Request in progress. Will wait a total of %s more seconds before timing out. Current Status='%s'
Expand Down
53 changes: 37 additions & 16 deletions src/commands/package/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,39 @@ export class PackageConvert extends SfCommand<PackageVersionCreateRequestResult>
summary: messages.getMessage('flags.seed-metadata.summary'),
description: messages.getMessage('flags.seed-metadata.description'),
}),
verbose: Flags.boolean({
summary: messages.getMessage('flags.verbose.summary'),
}),
};

public async run(): Promise<PackageVersionCreateRequestResult> {
const { flags } = await this.parse(PackageConvert);
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on(PackageEvents.convert.progress, async (data: PackageVersionCreateEventData) => {
this.spinner.status = messages.getMessage('in-progress', [
const inProgressMessage = messages.getMessage('in-progress', [
data.timeRemaining?.seconds,
camelCaseToTitleCase(data.packageVersionCreateRequestResult.Status),
]);
this.display(inProgressMessage, flags.verbose);
});

// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on(PackageEvents.convert.success, async () => {
this.spinner.status = 'SUCCESS';
this.display('SUCCESS', flags.verbose);
});

this.spinner.start('Converting Package', 'Initializing');
if (flags.verbose) {
this.log('Converting Package');
} else {
this.spinner.start('Converting Package', 'Initializing');
}
// initialize the project instance if in a project
let project: Optional<SfProject>;
try {
project = await SfProject.resolve();
} catch (err) {
// ignore project is optional
}
this.spinner.status = 'Converting Package';
const result = await Package.convert(
flags.package,
flags['target-dev-hub'].getConnection(flags['api-version']),
Expand All @@ -125,26 +132,40 @@ export class PackageConvert extends SfCommand<PackageVersionCreateRequestResult>
case 'Error':
this.spinner.stop();
throw new SfError(result.Error?.join('\n') ?? pvcMessages.getMessage('unknownError'));
case 'Success':
this.spinner.stop(
pvcMessages.getMessage(result.Status, [
result.Id,
result.SubscriberPackageVersionId,
INSTALL_URL_BASE.toString(),
result.SubscriberPackageVersionId,
this.config.bin,
])
);
case 'Success': {
const successMessage = pvcMessages.getMessage(result.Status, [
result.Id,
result.SubscriberPackageVersionId,
INSTALL_URL_BASE.toString(),
result.SubscriberPackageVersionId,
this.config.bin,
])
if (flags.verbose) {
this.log(successMessage);
} else {
this.spinner.stop(successMessage);
}
break;
default:
this.spinner.status = pvcMessages.getMessage('InProgress', [
}
default: {
const inProgressMessage = pvcMessages.getMessage('InProgress', [
this.config.bin,
camelCaseToTitleCase(result.Status),
result.Id,
]);
this.display(inProgressMessage, flags.verbose);
}
}

this.spinner.stop();
return result;
}

private display(message: string, verbose: boolean): void {
if (verbose) {
this.log(message);
} else {
this.spinner.status = message;
}
}
}

0 comments on commit 5aa8372

Please sign in to comment.