Skip to content

Commit 5ec3d58

Browse files
authored
Sm/tracking-management (#868)
* feat: commands to enable/disable tracking on an org * chore: snapshot and schema * docs: pjson topics
1 parent e285e01 commit 5ec3d58

File tree

9 files changed

+342
-60
lines changed

9 files changed

+342
-60
lines changed

command-snapshot.json

Lines changed: 75 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[
22
{
3+
"alias": [],
34
"command": "force:org:clone",
4-
"plugin": "@salesforce/plugin-org",
5+
"flagAliases": ["apiversion", "targetusername", "u"],
6+
"flagChars": ["a", "f", "o", "s", "t", "w"],
57
"flags": [
68
"api-version",
79
"definitionfile",
@@ -13,13 +15,13 @@
1315
"type",
1416
"wait"
1517
],
16-
"alias": [],
17-
"flagChars": ["a", "f", "o", "s", "t", "w"],
18-
"flagAliases": ["apiversion", "targetusername", "u"]
18+
"plugin": "@salesforce/plugin-org"
1919
},
2020
{
21+
"alias": [],
2122
"command": "force:org:create",
22-
"plugin": "@salesforce/plugin-org",
23+
"flagAliases": ["apiversion", "targetdevhubusername", "targetusername", "u"],
24+
"flagChars": ["a", "c", "d", "f", "i", "n", "o", "s", "t", "v", "w"],
2325
"flags": [
2426
"api-version",
2527
"clientid",
@@ -37,29 +39,29 @@
3739
"type",
3840
"wait"
3941
],
40-
"alias": [],
41-
"flagChars": ["a", "c", "d", "f", "i", "n", "o", "s", "t", "v", "w"],
42-
"flagAliases": ["apiversion", "targetdevhubusername", "targetusername", "u"]
42+
"plugin": "@salesforce/plugin-org"
4343
},
4444
{
45-
"command": "force:org:delete",
46-
"plugin": "@salesforce/plugin-org",
47-
"flags": ["api-version", "json", "loglevel", "no-prompt", "target-org", "targetdevhubusername"],
4845
"alias": [],
46+
"command": "force:org:delete",
47+
"flagAliases": ["apiversion", "noprompt", "targetusername", "u"],
4948
"flagChars": ["o", "p", "v"],
50-
"flagAliases": ["apiversion", "noprompt", "targetusername", "u"]
49+
"flags": ["api-version", "json", "loglevel", "no-prompt", "target-org", "targetdevhubusername"],
50+
"plugin": "@salesforce/plugin-org"
5151
},
5252
{
53-
"command": "force:org:status",
54-
"plugin": "@salesforce/plugin-org",
55-
"flags": ["api-version", "json", "loglevel", "sandboxname", "setalias", "setdefaultusername", "target-org", "wait"],
5653
"alias": [],
54+
"command": "force:org:status",
55+
"flagAliases": ["apiversion", "targetusername", "u"],
5756
"flagChars": ["a", "n", "o", "s", "w"],
58-
"flagAliases": ["apiversion", "targetusername", "u"]
57+
"flags": ["api-version", "json", "loglevel", "sandboxname", "setalias", "setdefaultusername", "target-org", "wait"],
58+
"plugin": "@salesforce/plugin-org"
5959
},
6060
{
61+
"alias": ["env:create:sandbox"],
6162
"command": "org:create:sandbox",
62-
"plugin": "@salesforce/plugin-org",
63+
"flagAliases": [],
64+
"flagChars": ["a", "c", "f", "i", "l", "n", "o", "s", "w"],
6365
"flags": [
6466
"alias",
6567
"async",
@@ -75,13 +77,13 @@
7577
"target-org",
7678
"wait"
7779
],
78-
"alias": ["env:create:sandbox"],
79-
"flagChars": ["a", "c", "f", "i", "l", "n", "o", "s", "w"],
80-
"flagAliases": []
80+
"plugin": "@salesforce/plugin-org"
8181
},
8282
{
83+
"alias": ["env:create:scratch"],
8384
"command": "org:create:scratch",
84-
"plugin": "@salesforce/plugin-org",
85+
"flagAliases": [],
86+
"flagChars": ["a", "c", "d", "e", "f", "i", "m", "t", "v", "w", "y"],
8587
"flags": [
8688
"admin-email",
8789
"alias",
@@ -104,80 +106,94 @@
104106
"username",
105107
"wait"
106108
],
107-
"alias": ["env:create:scratch"],
108-
"flagChars": ["a", "c", "d", "e", "f", "i", "m", "t", "v", "w", "y"],
109-
"flagAliases": []
109+
"plugin": "@salesforce/plugin-org"
110110
},
111111
{
112-
"command": "org:delete:sandbox",
113-
"plugin": "@salesforce/plugin-org",
114-
"flags": ["json", "no-prompt", "target-org"],
115112
"alias": ["env:delete:sandbox"],
113+
"command": "org:delete:sandbox",
114+
"flagAliases": ["targetusername", "u"],
116115
"flagChars": ["o", "p"],
117-
"flagAliases": ["targetusername", "u"]
116+
"flags": ["json", "no-prompt", "target-org"],
117+
"plugin": "@salesforce/plugin-org"
118118
},
119119
{
120-
"command": "org:delete:scratch",
121-
"plugin": "@salesforce/plugin-org",
122-
"flags": ["json", "no-prompt", "target-org"],
123120
"alias": ["env:delete:scratch"],
121+
"command": "org:delete:scratch",
122+
"flagAliases": ["targetusername", "u"],
124123
"flagChars": ["o", "p"],
125-
"flagAliases": ["targetusername", "u"]
124+
"flags": ["json", "no-prompt", "target-org"],
125+
"plugin": "@salesforce/plugin-org"
126+
},
127+
{
128+
"alias": [],
129+
"command": "org:disable:tracking",
130+
"flagAliases": [],
131+
"flagChars": ["o"],
132+
"flags": ["json", "target-org"],
133+
"plugin": "@salesforce/plugin-org"
126134
},
127135
{
136+
"alias": ["force:org:display"],
128137
"command": "org:display",
129-
"plugin": "@salesforce/plugin-org",
138+
"flagAliases": ["apiversion", "targetusername", "u"],
139+
"flagChars": ["o"],
130140
"flags": ["api-version", "json", "loglevel", "target-org", "verbose"],
131-
"alias": ["force:org:display"],
141+
"plugin": "@salesforce/plugin-org"
142+
},
143+
{
144+
"alias": [],
145+
"command": "org:enable:tracking",
146+
"flagAliases": [],
132147
"flagChars": ["o"],
133-
"flagAliases": ["apiversion", "targetusername", "u"]
148+
"flags": ["json", "target-org"],
149+
"plugin": "@salesforce/plugin-org"
134150
},
135151
{
136-
"command": "org:list",
137-
"plugin": "@salesforce/plugin-org",
138-
"flags": ["all", "clean", "json", "loglevel", "no-prompt", "skip-connection-status", "verbose"],
139152
"alias": ["force:org:list"],
153+
"command": "org:list",
154+
"flagAliases": ["noprompt", "skipconnectionstatus"],
140155
"flagChars": ["p"],
141-
"flagAliases": ["noprompt", "skipconnectionstatus"]
156+
"flags": ["all", "clean", "json", "loglevel", "no-prompt", "skip-connection-status", "verbose"],
157+
"plugin": "@salesforce/plugin-org"
142158
},
143159
{
144-
"command": "org:list:metadata",
145-
"plugin": "@salesforce/plugin-org",
146-
"flags": ["api-version", "folder", "json", "loglevel", "metadata-type", "output-file", "target-org"],
147160
"alias": ["force:mdapi:listmetadata"],
161+
"command": "org:list:metadata",
162+
"flagAliases": ["a", "apiversion", "metadatatype", "resultfile", "targetusername", "u"],
148163
"flagChars": ["f", "m", "o"],
149-
"flagAliases": ["a", "apiversion", "metadatatype", "resultfile", "targetusername", "u"]
164+
"flags": ["api-version", "folder", "json", "loglevel", "metadata-type", "output-file", "target-org"],
165+
"plugin": "@salesforce/plugin-org"
150166
},
151167
{
152-
"command": "org:list:metadata-types",
153-
"plugin": "@salesforce/plugin-org",
154-
"flags": ["api-version", "filter-known", "json", "loglevel", "output-file", "target-org"],
155168
"alias": ["force:mdapi:describemetadata"],
169+
"command": "org:list:metadata-types",
170+
"flagAliases": ["a", "apiversion", "filterknown", "resultfile", "targetusername", "u"],
156171
"flagChars": ["f", "k", "o"],
157-
"flagAliases": ["a", "apiversion", "filterknown", "resultfile", "targetusername", "u"]
172+
"flags": ["api-version", "filter-known", "json", "loglevel", "output-file", "target-org"],
173+
"plugin": "@salesforce/plugin-org"
158174
},
159175
{
160-
"command": "org:open",
161-
"plugin": "@salesforce/plugin-org",
162-
"flags": ["api-version", "browser", "json", "loglevel", "path", "source-file", "target-org", "url-only"],
163176
"alias": ["force:org:open", "force:source:open"],
177+
"command": "org:open",
178+
"flagAliases": ["apiversion", "sourcefile", "targetusername", "u", "urlonly"],
164179
"flagChars": ["b", "f", "o", "p", "r"],
165-
"flagAliases": ["apiversion", "sourcefile", "targetusername", "u", "urlonly"]
180+
"flags": ["api-version", "browser", "json", "loglevel", "path", "source-file", "target-org", "url-only"],
181+
"plugin": "@salesforce/plugin-org"
166182
},
167183
{
168-
"command": "org:resume:sandbox",
169-
"plugin": "@salesforce/plugin-org",
170-
"flags": ["job-id", "json", "name", "target-org", "use-most-recent", "wait"],
171184
"alias": ["env:resume:sandbox"],
185+
"command": "org:resume:sandbox",
186+
"flagAliases": [],
172187
"flagChars": ["i", "l", "n", "o", "w"],
173-
"flagAliases": []
188+
"flags": ["job-id", "json", "name", "target-org", "use-most-recent", "wait"],
189+
"plugin": "@salesforce/plugin-org"
174190
},
175191
{
176-
"command": "org:resume:scratch",
177-
"plugin": "@salesforce/plugin-org",
178-
"flags": ["job-id", "json", "use-most-recent"],
179192
"alias": ["env:resume:scratch"],
193+
"command": "org:resume:scratch",
194+
"flagAliases": [],
180195
"flagChars": ["i", "r"],
181-
"flagAliases": []
196+
"flags": ["job-id", "json", "use-most-recent"],
197+
"plugin": "@salesforce/plugin-org"
182198
}
183199
]

messages/org.disable.tracking.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# summary
2+
3+
Disable source tracking in local auth file.
4+
5+
# description
6+
7+
This has no effect on the org. It stores the setting in the CLI's configuration file for this org so that no source tracking operations are executed when working with this org.
8+
9+
# examples
10+
11+
Disable tracking on an org using an alias
12+
13+
- <%= config.bin %> <%= command.id %> -o someAlias
14+
15+
Disable tracking on an org using a username
16+
17+
- <%= config.bin %> <%= command.id %> -o [email protected]
18+
19+
Disable tracking on your default org
20+
21+
- <%= config.bin %> <%= command.id %>
22+
23+
# success
24+
25+
Disabled source tracking for %s.

messages/org.enable.tracking.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# summary
2+
3+
Enable source tracking in local auth file.
4+
5+
# description
6+
7+
This has no effect on the org. It stores the setting in the CLI's configuration file for this org so that source tracking operations are executed when working with this org.
8+
9+
This command will throw an error if the org does not support tracking.
10+
11+
# examples
12+
13+
Enable tracking on an org using an alias
14+
15+
- <%= config.bin %> <%= command.id %> -o someAlias
16+
17+
Enable tracking on an org using a username
18+
19+
- <%= config.bin %> <%= command.id %> -o [email protected]
20+
21+
Enable tracking on your default org
22+
23+
- <%= config.bin %> <%= command.id %>
24+
25+
# success
26+
27+
Enabled source tracking for %s.
28+
29+
# error.TrackingNotAvailable
30+
31+
This org cannot enable source tracking because the SourceMember object is not available, or you do not have access to it.
32+
33+
# error.TrackingNotAvailable.actions
34+
35+
- If the org is a sandbox, make sure that your production org has Source Tracking enabled in sandboxes. See https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_setup_enable_source_tracking_sandboxes.htm.
36+
37+
- Make sure that your user can access the SourceMembers table via the tooling API.
38+
39+
- If the Org is a production org, source tracking cannot be enabled.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,15 @@
7070
},
7171
"delete": {
7272
"description": "Delete scratch orgs, sandboxes, org shapes, and org snapshots."
73+
},
74+
"enable": {
75+
"description": "Enable tracking on an org."
76+
},
77+
"disable": {
78+
"description": "Disable tracking on an org"
7379
}
74-
}
80+
},
81+
"external": true
7582
},
7683
"force": {
7784
"external": true,

schemas/org-disable-tracking.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/OrgDisableTrackingResult",
4+
"definitions": {
5+
"OrgDisableTrackingResult": {
6+
"type": "object",
7+
"properties": {
8+
"tracksSource": {
9+
"type": "boolean"
10+
},
11+
"username": {
12+
"type": "string"
13+
}
14+
},
15+
"required": ["tracksSource", "username"],
16+
"additionalProperties": false
17+
}
18+
}
19+
}

schemas/org-enable-tracking.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/OrgEnableTrackingResult",
4+
"definitions": {
5+
"OrgEnableTrackingResult": {
6+
"type": "object",
7+
"properties": {
8+
"tracksSource": {
9+
"type": "boolean"
10+
},
11+
"username": {
12+
"type": "string"
13+
}
14+
},
15+
"required": ["tracksSource", "username"],
16+
"additionalProperties": false
17+
}
18+
}
19+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2023, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
import { dirname } from 'node:path';
8+
import { fileURLToPath } from 'node:url';
9+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
10+
import { Messages } from '@salesforce/core';
11+
12+
Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
13+
const messages = Messages.loadMessages('@salesforce/plugin-org', 'org.disable.tracking');
14+
15+
export type OrgDisableTrackingResult = {
16+
tracksSource: boolean;
17+
username: string;
18+
};
19+
20+
export default class OrgDisableTracking extends SfCommand<OrgDisableTrackingResult> {
21+
public static readonly summary = messages.getMessage('summary');
22+
public static readonly description = messages.getMessage('description');
23+
public static readonly examples = messages.getMessages('examples');
24+
25+
public static readonly flags = {
26+
'target-org': Flags.requiredOrg(),
27+
};
28+
29+
public async run(): Promise<OrgDisableTrackingResult> {
30+
const { flags } = await this.parse(OrgDisableTracking);
31+
await flags['target-org'].setTracksSource(false);
32+
this.logSuccess(messages.getMessage('success', [flags['target-org'].getUsername()]));
33+
return {
34+
tracksSource: await flags['target-org'].tracksSource(),
35+
username: flags['target-org'].getUsername() as string,
36+
};
37+
}
38+
}

0 commit comments

Comments
 (0)