-
-
Save FabienTaillon/3330787a790910dbaece67b0a8e81d4a to your computer and use it in GitHub Desktop.
new.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
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