generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinfo.ts
More file actions
96 lines (77 loc) · 3.56 KB
/
info.ts
File metadata and controls
96 lines (77 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as os from 'os';
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages, SfdxError } from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
// 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('@salesforce/plugin-omnistudio-migration-tool', 'info');
export default class Org extends SfdxCommand {
public static description = messages.getMessage('commandDescription');
public static examples = messages.getMessage('examples').split(os.EOL);
public static args = [{ name: 'file' }];
protected static flagsConfig = {
// flag with a value (-n, --name=VALUE)
name: flags.string({
char: 'n',
description: messages.getMessage('nameFlagDescription'),
}),
allversions: flags.boolean({
char: 'a',
description: messages.getMessage('allVersionsDescription'),
required: false,
}),
};
// Comment this out if your command does not require an org username
protected static requiresUsername = true;
// Comment this out if your command does not support a hub org username
protected static supportsDevhubUsername = true;
// Set this to true if your command requires a project workspace; 'requiresProject' is false by default
protected static requiresProject = false;
public async run(): Promise<AnyJson> {
const name = (this.flags.name || 'world') as string;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const allVersions = this.flags.allversions || false;
// this.org is guaranteed because requiresUsername=true, as opposed to supportsUsername
const conn = this.org.getConnection();
const query = 'Select Name, TrialExpirationDate from Organization';
// The type we are querying for
interface Organization {
Name: string;
TrialExpirationDate: string;
}
// Query the org
const result = await conn.query<Organization>(query);
// Organization will always return one result, but this is an example of throwing an error
// The output and --json will automatically be handled for you.
if (!result.records || result.records.length <= 0) {
throw new SfdxError(messages.getMessage('errorNoOrgResults', [this.org.getOrgId()]));
}
// Organization always only returns one result
const orgName = result.records[0].Name;
const trialExpirationDate = result.records[0].TrialExpirationDate;
let outputString = `Hello ${name}! This is org: ${orgName}`;
if (trialExpirationDate) {
const date = new Date(trialExpirationDate).toDateString();
outputString = `${outputString} and I will be around until ${date}!`;
}
this.ux.log(outputString);
// this.hubOrg is NOT guaranteed because supportsHubOrgUsername=true, as opposed to requiresHubOrgUsername.
if (this.hubOrg) {
const hubOrgId = this.hubOrg.getOrgId();
this.ux.log(`My hub org id is: ${hubOrgId}`);
}
if (allVersions) {
outputString = `${outputString} and all versions will be migrated`;
}
// Return an object to be displayed with --json
return { orgId: this.org.getOrgId(), outputString };
}
}