Skip to content

Commit 8a396de

Browse files
alan-agius4dgp1130
authored andcommitted
fix(@angular/cli): print entire config when no positional args are provided to ng config
This fixes a regression were when no positional args are provided to `ng config` the entire config file should to be printed in the console.
1 parent 5a8bdeb commit 8a396de

3 files changed

Lines changed: 42 additions & 34 deletions

File tree

‎packages/angular/cli/src/commands/config/cli.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { getWorkspaceRaw, validateWorkspace } from '../../utilities/config';
2020
import { JSONFile, parseJson } from '../../utilities/json-file';
2121

2222
interface ConfigCommandArgs {
23-
'json-path': string;
23+
'json-path'?: string;
2424
value?: string;
2525
global?: boolean;
2626
}
@@ -29,7 +29,7 @@ export class ConfigCommandModule
2929
extends CommandModule<ConfigCommandArgs>
3030
implements CommandModuleImplementation<ConfigCommandArgs>
3131
{
32-
command = 'config <json-path> [value]';
32+
command = 'config [json-path] [value]';
3333
describe =
3434
'Retrieves or sets Angular configuration values in the angular.json file for the workspace.';
3535
longDescriptionPath = join(__dirname, 'long-description.md');
@@ -41,7 +41,6 @@ export class ConfigCommandModule
4141
`The configuration key to set or query, in JSON path format. ` +
4242
`For example: "a[3].foo.bar[2]". If no new value is provided, returns the current value of this key.`,
4343
type: 'string',
44-
demandOption: true,
4544
})
4645
.positional('value', {
4746
description: 'If provided, a new value for the given configuration key.',
Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
11
import { ng } from '../../../utils/process';
22
import { expectToFail } from '../../../utils/utils';
33

4+
export default async function () {
5+
await expectToFail(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle'));
6+
await ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false');
7+
const { stdout } = await ng('config', 'schematics.@schematics/angular.component.inlineStyle');
8+
if (!stdout.match(/false\n?/)) {
9+
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
10+
}
411

5-
export default function() {
6-
return Promise.resolve()
7-
.then(() => expectToFail(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle')))
8-
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false'))
9-
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle'))
10-
.then(({ stdout }) => {
11-
if (!stdout.match(/false\n?/)) {
12-
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
13-
}
14-
})
15-
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'true'))
16-
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle'))
17-
.then(({ stdout }) => {
18-
if (!stdout.match(/true\n?/)) {
19-
throw new Error(`Expected "true", received "${JSON.stringify(stdout)}".`);
20-
}
21-
})
22-
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false'))
23-
.then(() => ng('config', `projects.test-project.architect.build.options.assets[0]`))
24-
.then(({ stdout }) => {
25-
if (!stdout.includes('src/favicon.ico')) {
26-
throw new Error(`Expected "src/favicon.ico", received "${JSON.stringify(stdout)}".`);
27-
}
28-
})
29-
.then(() => ng('config', `projects["test-project"].architect.build.options.assets[0]`))
30-
.then(({ stdout }) => {
31-
if (!stdout.includes('src/favicon.ico')) {
32-
throw new Error(`Expected "src/favicon.ico", received "${JSON.stringify(stdout)}".`);
33-
}
34-
});
12+
await ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'true');
13+
const { stdout: stdout1 } = await ng(
14+
'config',
15+
'schematics.@schematics/angular.component.inlineStyle',
16+
);
17+
if (!stdout1.match(/true\n?/)) {
18+
throw new Error(`Expected "true", received "${JSON.stringify(stdout)}".`);
19+
}
20+
21+
await ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false');
22+
const { stdout: stdout2 } = await ng(
23+
'config',
24+
`projects.test-project.architect.build.options.assets[0]`,
25+
);
26+
if (!stdout2.includes('src/favicon.ico')) {
27+
throw new Error(`Expected "src/favicon.ico", received "${JSON.stringify(stdout)}".`);
28+
}
29+
30+
const { stdout: stdout3 } = await ng(
31+
'config',
32+
`projects["test-project"].architect.build.options.assets[0]`,
33+
);
34+
35+
if (!stdout3.includes('src/favicon.ico')) {
36+
throw new Error(`Expected "src/favicon.ico", received "${JSON.stringify(stdout)}".`);
37+
}
38+
39+
// should print all config when no positional args are provided.
40+
const { stdout: stdout4 } = await ng('config');
41+
if (!stdout4.includes('$schema')) {
42+
throw new Error(`Expected to contain "$schema", received "${JSON.stringify(stdout)}".`);
43+
}
3544
}

‎tests/legacy-cli/e2e/tests/commands/help/help-json.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default async function () {
44
// This test is use as a sanity check.
55
const addHelpOutputSnapshot = JSON.stringify({
66
'name': 'config',
7-
'command': 'ng config <json-path> [value]',
7+
'command': 'ng config [json-path] [value]',
88
'shortDescription':
99
'Retrieves or sets Angular configuration values in the angular.json file for the workspace.',
1010
'longDescriptionRelativePath': '@angular/cli/src/commands/config/long-description.md',

0 commit comments

Comments
 (0)