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: Adds verbose option to package convert #477

Merged
merged 2 commits into from
Oct 31, 2023
Merged
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 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;
}
}
}