Skip to content

Instantly share code, notes, and snippets.

@FabienTaillon
Last active September 5, 2023 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FabienTaillon/3330787a790910dbaece67b0a8e81d4a to your computer and use it in GitHub Desktop.
Save FabienTaillon/3330787a790910dbaece67b0a8e81d4a to your computer and use it in GitHub Desktop.
new.ts
import {
Flags,
SfCommand,
orgApiVersionFlagWithDeprecations,
requiredOrgFlagWithDeprecations,
requiredHubFlagWithDeprecations,
} from '@salesforce/sf-plugins-core';
import { Messages, SfError } from '@salesforce/core';
import { QueryResult, Record } from 'jsforce';
// Initialize Messages with the current plugin directory
Messages.importMessagesDirectory(__dirname);
// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
// or any library that is using the messages framework can also be loaded this way.
const messages = Messages.loadMessages('texei', 'command.new');
export type NewCommandResult = {
message: string;
};
export default class NewCommand extends SfCommand<NewCommandResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly examples = ['$ sf texei command new --target-org richard.hendricks@piedpiper.com'];
public static readonly flags = {
'target-org': requiredOrgFlagWithDeprecations,
'target-dev-hub': requiredHubFlagWithDeprecations,
'api-version': orgApiVersionFlagWithDeprecations,
wait: Flags.integer({ char: 'w', summary: messages.getMessage('flags.wait.summary'), required: false }), // Not used but just to show a flags
};
// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
public static readonly requiresProject = true;
public async run(): Promise<NewCommandResult> {
const { flags } = await this.parse(NewCommand);
this.spinner.start('Starting command', undefined, { stdout: true });
const conn = flags['target-org'].getConnection(flags['api-version']);
let orgName;
try {
const orgInfos: QueryResult<Record> = await conn.query('SELECT Name FROM Organization LIMIT 1');
orgName = orgInfos.records[0].Name as string;
} catch (exception) {
throw new SfError('Something went wrong');
}
this.spinner.stop('Done.');
const orgMessage = `Org Name: ${orgName}`;
this.log(orgMessage);
return { message: orgMessage };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment