Skip to content

Commit 27cbc3a

Browse files
committed
Allow config override through --config or env.SOCKET_CLI_CONFIG
1 parent b6ac3d0 commit 27cbc3a

Some content is hidden

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

56 files changed

+1540
-745
lines changed

src/commands/analytics/cmd-analytics.test.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ describe('socket analytics', async () => {
1111
// Lazily access constants.rootBinPath.
1212
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
1313

14-
cmdit(['analytics', '--help'], 'should support --help', async cmd => {
15-
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
16-
expect(stdout).toMatchInlineSnapshot(
17-
`
14+
cmdit(
15+
['analytics', '--help', '--config', '{}'],
16+
'should support --help',
17+
async cmd => {
18+
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
19+
expect(stdout).toMatchInlineSnapshot(
20+
`
1821
"Look up analytics data
1922
2023
Usage
@@ -38,23 +41,24 @@ describe('socket analytics', async () => {
3841
$ socket analytics --scope=org --time=30
3942
$ socket analytics --scope=repo --repo=test-repo --time=30"
4043
`
41-
)
42-
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
44+
)
45+
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
4346
"
4447
_____ _ _ /---------------
4548
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
4649
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
4750
|_____|___|___|_,_|___|_|.dev | Command: \`socket analytics\`, cwd: <redacted>"
4851
`)
4952

50-
expect(code, 'help should exit with code 2').toBe(2)
51-
expect(stderr, 'header should include command (without params)').toContain(
52-
'`socket analytics`'
53-
)
54-
})
53+
expect(code, 'help should exit with code 2').toBe(2)
54+
expect(stderr, 'banner includes base command').toContain(
55+
'`socket analytics`'
56+
)
57+
}
58+
)
5559

5660
cmdit(
57-
['analytics', '--dry-run'],
61+
['analytics', '--dry-run', '--config', '{}'],
5862
'should require args with just dry-run',
5963
async cmd => {
6064
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)

src/commands/audit-log/cmd-audit-log.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ describe('socket audit-log', async () => {
1111
// Lazily access constants.rootBinPath.
1212
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
1313

14-
cmdit(['audit-log', '--help'], 'should support --help', async cmd => {
15-
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
16-
expect(stdout).toMatchInlineSnapshot(
17-
`
14+
cmdit(
15+
['audit-log', '--help', '--config', '{}'],
16+
'should support --help',
17+
async cmd => {
18+
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
19+
expect(stdout).toMatchInlineSnapshot(
20+
`
1821
"Look up the audit log for an organization
1922
2023
Usage
@@ -35,23 +38,24 @@ describe('socket audit-log', async () => {
3538
Examples
3639
$ socket audit-log FakeOrg"
3740
`
38-
)
39-
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
41+
)
42+
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
4043
"
4144
_____ _ _ /---------------
4245
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
4346
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
4447
|_____|___|___|_,_|___|_|.dev | Command: \`socket audit-log\`, cwd: <redacted>"
4548
`)
4649

47-
expect(code, 'help should exit with code 2').toBe(2)
48-
expect(stderr, 'header should include command (without params)').toContain(
49-
'`socket audit-log`'
50-
)
51-
})
50+
expect(code, 'help should exit with code 2').toBe(2)
51+
expect(stderr, 'banner includes base command').toContain(
52+
'`socket audit-log`'
53+
)
54+
}
55+
)
5256

5357
cmdit(
54-
['audit-log', '--dry-run'],
58+
['audit-log', '--dry-run', '--config', '{}'],
5559
'should require args with just dry-run',
5660
async cmd => {
5761
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
@@ -73,7 +77,7 @@ describe('socket audit-log', async () => {
7377
)
7478

7579
cmdit(
76-
['audit-log', 'fakeorg', '--dry-run'],
80+
['audit-log', 'fakeorg', '--dry-run', '--config', '{}'],
7781
'should require args with just dry-run',
7882
async cmd => {
7983
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)

src/commands/cdxgen/cmd-cdxgen.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,12 @@ describe('socket cdxgen', async () => {
8181

8282
// expect(code, 'help should exit with code 2').toBe(2)
8383
expect(code, 'help should exit with code 2').toBe(0) // cdxgen special case
84-
expect(stderr, 'header should include command (without params)').toContain(
85-
'`socket cdxgen`'
86-
)
84+
expect(stderr, 'banner includes base command').toContain('`socket cdxgen`')
8785
})
8886

8987
// cdxgen does not support --dry-run
9088
// cmdit(
91-
// ['cdxgen', '--dry-run'],
89+
// ['cdxgen', '--help', '--config', '{}'],
9290
// 'should require args with just dry-run',
9391
// async cmd => {
9492
// const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)

src/commands/config/cmd-config-get.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ describe('socket config get', async () => {
1111
// Lazily access constants.rootBinPath.
1212
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
1313

14-
cmdit(['config', 'get', '--help'], 'should support --help', async cmd => {
15-
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
16-
expect(stdout).toMatchInlineSnapshot(
17-
`
14+
cmdit(
15+
['config', 'get', '--help', '--config', '{}'],
16+
'should support --help',
17+
async cmd => {
18+
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
19+
expect(stdout).toMatchInlineSnapshot(
20+
`
1821
"Get the value of a local CLI config item
1922
2023
Usage
@@ -37,23 +40,24 @@ describe('socket config get', async () => {
3740
Examples
3841
$ socket config get FakeOrg --repoName=test-repo"
3942
`
40-
)
41-
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
43+
)
44+
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
4245
"
4346
_____ _ _ /---------------
4447
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
4548
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
4649
|_____|___|___|_,_|___|_|.dev | Command: \`socket config get\`, cwd: <redacted>"
4750
`)
4851

49-
expect(code, 'help should exit with code 2').toBe(2)
50-
expect(stderr, 'header should include command (without params)').toContain(
51-
'`socket config get`'
52-
)
53-
})
52+
expect(code, 'help should exit with code 2').toBe(2)
53+
expect(stderr, 'banner includes base command').toContain(
54+
'`socket config get`'
55+
)
56+
}
57+
)
5458

5559
cmdit(
56-
['config', 'get', '--dry-run'],
60+
['config', 'get', '--dry-run', '--config', '{}'],
5761
'should require args with just dry-run',
5862
async cmd => {
5963
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
@@ -75,7 +79,7 @@ describe('socket config get', async () => {
7579
)
7680

7781
cmdit(
78-
['config', 'get', 'test', '--dry-run'],
82+
['config', 'get', 'test', '--dry-run', '--config', '{}'],
7983
'should require args with just dry-run',
8084
async cmd => {
8185
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)

src/commands/config/cmd-config-list.test.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ describe('socket config get', async () => {
1111
// Lazily access constants.rootBinPath.
1212
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
1313

14-
cmdit(['config', 'list', '--help'], 'should support --help', async cmd => {
15-
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
16-
expect(stdout).toMatchInlineSnapshot(
17-
`
14+
cmdit(
15+
['config', 'list', '--help', '--config', '{}'],
16+
'should support --help',
17+
async cmd => {
18+
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
19+
expect(stdout).toMatchInlineSnapshot(
20+
`
1821
"Show all local CLI config items and their values
1922
2023
Usage
@@ -38,23 +41,24 @@ describe('socket config get', async () => {
3841
Examples
3942
$ socket config list FakeOrg --repoName=test-repo"
4043
`
41-
)
42-
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
44+
)
45+
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
4346
"
4447
_____ _ _ /---------------
4548
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
4649
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
4750
|_____|___|___|_,_|___|_|.dev | Command: \`socket config list\`, cwd: <redacted>"
4851
`)
4952

50-
expect(code, 'help should exit with code 2').toBe(2)
51-
expect(stderr, 'header should include command (without params)').toContain(
52-
'`socket config list`'
53-
)
54-
})
53+
expect(code, 'help should exit with code 2').toBe(2)
54+
expect(stderr, 'banner includes base command').toContain(
55+
'`socket config list`'
56+
)
57+
}
58+
)
5559

5660
cmdit(
57-
['config', 'list', '--dry-run'],
61+
['config', 'list', '--dry-run', '--config', '{}'],
5862
'should require args with just dry-run',
5963
async cmd => {
6064
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)

src/commands/config/cmd-config-set.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ describe('socket config get', async () => {
1111
// Lazily access constants.rootBinPath.
1212
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
1313

14-
cmdit(['config', 'set', '--help'], 'should support --help', async cmd => {
15-
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
16-
expect(stdout).toMatchInlineSnapshot(
17-
`
14+
cmdit(
15+
['config', 'set', '--help', '--config', '{}'],
16+
'should support --help',
17+
async cmd => {
18+
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
19+
expect(stdout).toMatchInlineSnapshot(
20+
`
1821
"Update the value of a local CLI config item
1922
2023
Usage
@@ -42,23 +45,24 @@ describe('socket config get', async () => {
4245
Examples
4346
$ socket config set apiProxy https://example.com"
4447
`
45-
)
46-
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
48+
)
49+
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
4750
"
4851
_____ _ _ /---------------
4952
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
5053
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
5154
|_____|___|___|_,_|___|_|.dev | Command: \`socket config set\`, cwd: <redacted>"
5255
`)
5356

54-
expect(code, 'help should exit with code 2').toBe(2)
55-
expect(stderr, 'header should include command (without params)').toContain(
56-
'`socket config set`'
57-
)
58-
})
57+
expect(code, 'help should exit with code 2').toBe(2)
58+
expect(stderr, 'banner includes base command').toContain(
59+
'`socket config set`'
60+
)
61+
}
62+
)
5963

6064
cmdit(
61-
['config', 'set', '--dry-run'],
65+
['config', 'set', '--dry-run', '--config', '{}'],
6266
'should require args with just dry-run',
6367
async cmd => {
6468
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
@@ -82,7 +86,7 @@ describe('socket config get', async () => {
8286
)
8387

8488
cmdit(
85-
['config', 'set', 'test', 'xyz', '--dry-run'],
89+
['config', 'set', 'test', 'xyz', '--dry-run', '--config', '{}'],
8690
'should require args with just dry-run',
8791
async cmd => {
8892
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)

src/commands/config/cmd-config-unset.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ describe('socket config unset', async () => {
1111
// Lazily access constants.rootBinPath.
1212
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
1313

14-
cmdit(['config', 'unset', '--help'], 'should support --help', async cmd => {
15-
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
16-
expect(stdout).toMatchInlineSnapshot(
17-
`
14+
cmdit(
15+
['config', 'unset', '--help', '--config', '{}'],
16+
'should support --help',
17+
async cmd => {
18+
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
19+
expect(stdout).toMatchInlineSnapshot(
20+
`
1821
"Clear the value of a local CLI config item
1922
2023
Usage
@@ -37,23 +40,24 @@ describe('socket config unset', async () => {
3740
Examples
3841
$ socket config unset FakeOrg --repoName=test-repo"
3942
`
40-
)
41-
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
43+
)
44+
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
4245
"
4346
_____ _ _ /---------------
4447
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
4548
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
4649
|_____|___|___|_,_|___|_|.dev | Command: \`socket config unset\`, cwd: <redacted>"
4750
`)
4851

49-
expect(code, 'help should exit with code 2').toBe(2)
50-
expect(stderr, 'header should include command (without params)').toContain(
51-
'`socket config unset`'
52-
)
53-
})
52+
expect(code, 'help should exit with code 2').toBe(2)
53+
expect(stderr, 'banner includes base command').toContain(
54+
'`socket config unset`'
55+
)
56+
}
57+
)
5458

5559
cmdit(
56-
['config', 'unset', '--dry-run'],
60+
['config', 'unset', '--dry-run', '--config', '{}'],
5761
'should require args with just dry-run',
5862
async cmd => {
5963
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
@@ -75,7 +79,7 @@ describe('socket config unset', async () => {
7579
)
7680

7781
cmdit(
78-
['config', 'unset', 'test', '--dry-run'],
82+
['config', 'unset', 'test', '--dry-run', '--config', '{}'],
7983
'should require args with just dry-run',
8084
async cmd => {
8185
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)

0 commit comments

Comments
 (0)