Skip to content

Commit e63ff43

Browse files
authored
fix: remove short flag -j for json and return response to global json handler (#465)
1 parent e157185 commit e63ff43

File tree

42 files changed

+247
-417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+247
-417
lines changed

src/commands/deploy/functions.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export default class DeployFunctions extends Command {
5353
description: messages.getMessage('flags.quiet.summary'),
5454
char: 'q',
5555
}),
56-
json: FunctionsFlagBuilder.json,
5756
};
5857

5958
async run() {
@@ -187,16 +186,9 @@ export default class DeployFunctions extends Command {
187186
cli.action.stop();
188187

189188
if (shouldExitNonZero) {
190-
cli.exit(1);
191-
}
192-
if (flags.json) {
193-
cli.styledJSON({
194-
status: 0,
195-
result: {
196-
results,
197-
},
198-
warnings: [],
199-
});
189+
this.exit(1);
200190
}
191+
192+
return results;
201193
}
202194
}

src/commands/env/compute/collaborator/add.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Messages.importMessagesDirectory(__dirname);
1616
const messages = Messages.loadMessages('@salesforce/plugin-functions', 'env.compute.collaborator.add');
1717

1818
export default class ComputeCollaboratorAdd extends Command {
19+
static enableJsonFlag = false;
20+
1921
static summary = messages.getMessage('summary');
2022

2123
static examples = messages.getMessages('examples');

src/commands/env/create/compute.ts

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export default class EnvCreateCompute extends Command {
3737
char: 'a',
3838
description: messages.getMessage('flags.alias.summary'),
3939
}),
40-
json: FunctionsFlagBuilder.json,
4140
};
4241

4342
async run() {
@@ -64,9 +63,7 @@ export default class EnvCreateCompute extends Command {
6463
)} to the "features" list in your scratch org definition JSON file, e.g. "features": ["Functions"]`
6564
);
6665
}
67-
if (!flags.json) {
68-
cli.action.start(`Creating compute environment for org ID ${orgId}`);
69-
}
66+
cli.action.start(`Creating compute environment for org ID ${orgId}`);
7067
const project = await fetchSfdxProject();
7168
const projectName = project.name;
7269

@@ -140,25 +137,21 @@ export default class EnvCreateCompute extends Command {
140137

141138
cli.action.stop();
142139

143-
if (!flags.json) {
144-
this.log(`New compute environment created with ID ${app.name}`);
140+
this.log(`New compute environment created with ID ${app.name}`);
145141

146-
cli.action.start('Connecting environments');
147-
}
142+
cli.action.start('Connecting environments');
148143

149144
if (alias) {
150145
this.stateAggregator.aliases.set(alias, app.id!);
151146
await this.stateAggregator.aliases.write();
152147
}
153148

154149
cli.action.stop();
155-
if (!flags.json) {
156-
this.log(
157-
alias
158-
? `Your compute environment with local alias ${herokuColor.cyan(alias)} is ready.`
159-
: 'Your compute environment is ready.'
160-
);
161-
}
150+
this.log(
151+
alias
152+
? `Your compute environment with local alias ${herokuColor.cyan(alias)} is ready.`
153+
: 'Your compute environment is ready.'
154+
);
162155
} catch (err) {
163156
const DUPLICATE_PROJECT_MESSAGE =
164157
'There is already a project with the same name in the same namespace for this org';
@@ -181,18 +174,12 @@ export default class EnvCreateCompute extends Command {
181174
this.error(`${error.data.message}`);
182175
}
183176
const app = await fetchAppForProject(this.client, projectName, org.getUsername());
184-
if (flags.json) {
185-
cli.styledJSON({
186-
status: 0,
187-
result: {
188-
alias,
189-
projectName,
190-
connectedOrgAlias: '',
191-
connectedOrgId: orgId,
192-
computeEnvironmentName: app.name,
193-
},
194-
warnings: [],
195-
});
196-
}
177+
return {
178+
alias,
179+
projectName,
180+
connectedOrgAlias: '',
181+
connectedOrgId: orgId,
182+
computeEnvironmentName: app.name,
183+
};
197184
}
198185
}

src/commands/env/delete.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export default class EnvDelete extends Command {
4040
hidden: true,
4141
}),
4242
confirm: confirmationFlag,
43-
json: FunctionsFlagBuilder.json,
4443
};
4544

4645
async run() {
@@ -59,7 +58,7 @@ export default class EnvDelete extends Command {
5958
}
6059

6160
if (flags.environment) {
62-
cli.warn(messages.getMessage('flags.environment.deprecation'));
61+
this.warn(messages.getMessage('flags.environment.deprecation'));
6362
}
6463

6564
await this.confirmRemovePrompt('environment', targetCompute, flags.confirm);
@@ -158,12 +157,6 @@ export default class EnvDelete extends Command {
158157

159158
cli.action.stop();
160159

161-
if (flags.json) {
162-
cli.styledJSON({
163-
status: 0,
164-
result: 'Environment deleted.',
165-
warnings: [],
166-
});
167-
}
160+
return 'Environment deleted.';
168161
}
169162
}

src/commands/env/log.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const messages = Messages.loadMessages('@salesforce/plugin-functions', 'env.log'
1919

2020
export default class Log extends Command {
2121
public static readonly state = 'beta';
22+
static enableJsonFlag = false;
23+
2224
static summary = messages.getMessage('summary');
2325

2426
static examples = messages.getMessages('examples');
@@ -54,7 +56,7 @@ export default class Log extends Command {
5456
}
5557

5658
if (flags.environment) {
57-
cli.warn(messages.getMessage('flags.environment.deprecation'));
59+
this.warn(messages.getMessage('flags.environment.deprecation'));
5860
}
5961

6062
const appName = await resolveAppNameForEnvironment(targetCompute);

src/commands/env/log/tail.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Messages.importMessagesDirectory(__dirname);
1818
const messages = Messages.loadMessages('@salesforce/plugin-functions', 'env.log.tail');
1919

2020
export default class LogTail extends Command {
21+
static enableJsonFlag = false;
22+
2123
static summary = messages.getMessage('summary');
2224

2325
static examples = messages.getMessages('examples');
@@ -48,7 +50,7 @@ export default class LogTail extends Command {
4850
}
4951

5052
if (flags.environment) {
51-
cli.warn(messages.getMessage('flags.environment.deprecation'));
53+
this.warn(messages.getMessage('flags.environment.deprecation'));
5254
}
5355

5456
const appName = await resolveAppNameForEnvironment(targetCompute);

src/commands/env/logdrain/add.ts

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export default class LogDrainAdd extends Command {
4343
description: messages.getMessage('flags.drain-url.summary'),
4444
hidden: true,
4545
}),
46-
json: FunctionsFlagBuilder.json,
4746
};
4847

4948
async run() {
@@ -71,58 +70,52 @@ export default class LogDrainAdd extends Command {
7170
}
7271

7372
if (flags.environment) {
74-
cli.warn(messages.getMessage('flags.environment.deprecation'));
73+
this.warn(messages.getMessage('flags.environment.deprecation'));
7574
}
7675

7776
if (flags.url) {
78-
cli.warn(messages.getMessage('flags.url.deprecation'));
77+
this.warn(messages.getMessage('flags.url.deprecation'));
7978
}
8079
const appName = await resolveAppNameForEnvironment(targetCompute);
8180

8281
try {
82+
cli.action.start(`Creating drain for environment ${herokuColor.app(targetCompute)}`);
83+
8384
const result = await this.client.post<Heroku.LogDrain>(`/apps/${appName}/log-drains`, {
8485
data: {
8586
url,
8687
},
8788
});
8889

89-
if (flags.json) {
90-
cli.styledJSON({
91-
status: 0,
92-
result: [
93-
{
94-
addon: null,
95-
created_at: result.data.created_at,
96-
id: result.data.id,
97-
token: result.data.token,
98-
updated_at: result.data.updated_at,
99-
url: result.data.url,
100-
},
101-
],
102-
warnings: [],
103-
});
104-
} else {
105-
cli.action.start(`Creating drain for environment ${herokuColor.app(targetCompute)}`);
106-
107-
cli.action.stop();
108-
}
90+
cli.action.stop();
91+
92+
return [
93+
{
94+
addon: null,
95+
created_at: result.data.created_at,
96+
id: result.data.id,
97+
token: result.data.token,
98+
updated_at: result.data.updated_at,
99+
url: result.data.url,
100+
},
101+
];
109102
} catch (e) {
110103
const error = e as { data: { message?: string } };
111104

112105
if (error.data?.message?.includes('Url is invalid')) {
113-
this.error(new Error(`URL is invalid <${url}>`));
106+
this.error(new Error(`URL is invalid ${url}`));
114107
}
115108

116109
if (error.data?.message?.includes('Url has already been taken')) {
117-
this.error(new Error(`Logdrain URL is already added <${url}>`));
110+
this.error(new Error(`Logdrain URL is already added ${url}`));
118111
}
119112

120-
if (error.data?.message?.includes("Couldn't find that app.")) {
121-
this.error(new Error(`Could not find environment <${appName}>`));
113+
if (error.data?.message?.includes("Couldn't find that app")) {
114+
this.error(new Error(`Could not find environment ${appName}`));
122115
}
123116

124117
if (error.data?.message?.includes("You've reached the limit")) {
125-
this.error(new Error(`You've reached the limit of 5 log drains on <${appName}>`));
118+
this.error(new Error(`You've reached the limit of 5 log drains on ${appName}`));
126119
}
127120

128121
if (error.data?.message?.includes('401')) {

src/commands/env/logdrain/list.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export default class LogDrainList extends Command {
3030
exclusive: ['target-compute'],
3131
hidden: true,
3232
}),
33-
json: FunctionsFlagBuilder.json,
3433
};
3534

3635
async run() {
@@ -49,35 +48,16 @@ export default class LogDrainList extends Command {
4948
}
5049

5150
if (flags.environment) {
52-
cli.warn(messages.getMessage('flags.environment.deprecation'));
51+
this.warn(messages.getMessage('flags.environment.deprecation'));
5352
}
5453

5554
const appName = await resolveAppNameForEnvironment(targetCompute);
5655

5756
const { data: drains } = await this.client.get<Heroku.LogDrain[]>(`/apps/${appName}/log-drains`);
5857

59-
if (flags.json) {
60-
if (drains.length === 0) {
61-
cli.styledJSON({
62-
status: 0,
63-
result: [],
64-
warnings: [`No logdrain found for environment <${appName}>`],
65-
});
66-
return;
67-
}
68-
69-
cli.styledJSON({
70-
status: 0,
71-
result: drains,
72-
warnings: [],
73-
});
74-
return;
58+
if (drains.length === 0) {
59+
this.warn(`No log-drains found for environment ${targetCompute}`);
7560
} else {
76-
if (drains.length === 0) {
77-
this.log(`No log drains found for environment ${targetCompute}.`);
78-
return;
79-
}
80-
8161
cli.table<Heroku.LogDrain>(
8262
drains,
8363
{
@@ -96,5 +76,7 @@ export default class LogDrainList extends Command {
9676
}
9777
);
9878
}
79+
80+
return drains;
9981
}
10082
}

src/commands/env/logdrain/remove.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export default class LogDrainRemove extends Command {
4343
description: messages.getMessage('flags.drain-url.summary'),
4444
hidden: true,
4545
}),
46-
json: FunctionsFlagBuilder.json,
4746
};
4847

4948
async run() {
@@ -63,41 +62,35 @@ export default class LogDrainRemove extends Command {
6362
}
6463

6564
if (!url) {
66-
this.error(new Error('Missing required flag: -u, --url Logdrain url to remove'));
65+
this.error(new Error('Missing required flag: -l, --drain-url Logdrain url to remove'));
6766
}
6867

6968
if (flags.environment) {
70-
cli.warn(messages.getMessage('flags.environment.deprecation'));
69+
this.warn(messages.getMessage('flags.environment.deprecation'));
7170
}
7271

7372
if (flags.url) {
74-
cli.warn(messages.getMessage('flags.url.deprecation'));
73+
this.warn(messages.getMessage('flags.url.deprecation'));
7574
}
7675

7776
const appName = await resolveAppNameForEnvironment(targetCompute);
7877
try {
78+
cli.action.start(`Deleting drain for environment ${herokuColor.app(targetCompute)}`);
79+
7980
await this.client.delete<Heroku.LogDrain>(`/apps/${appName}/log-drains/${encodeURIComponent(url)}`);
80-
if (flags.json) {
81-
cli.styledJSON({
82-
status: 0,
83-
result: null,
84-
warnings: [],
85-
});
86-
return;
87-
} else {
88-
cli.action.start(`Deleting drain for environment ${herokuColor.app(targetCompute)}`);
89-
90-
cli.action.stop();
91-
}
81+
82+
cli.action.stop();
83+
84+
return 'Removed drain-url';
9285
} catch (e) {
9386
const error = e as { data: { message?: string } };
9487

9588
if (error.data?.message?.includes('Url is invalid')) {
96-
this.error(new Error(`URL is invalid <${url}>`));
89+
this.error(new Error(`URL is invalid ${url}`));
9790
}
9891

9992
if (error.data?.message?.includes("Couldn't find that app.")) {
100-
this.error(new Error(`Couldn't find that app <${appName}>`));
93+
this.error(new Error(`Couldn't find that app ${appName}`));
10194
}
10295

10396
this.error(e as Error);

0 commit comments

Comments
 (0)