/
config.ts
107 lines (102 loc) · 2.65 KB
/
config.ts
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
97
98
99
100
101
102
103
104
105
106
107
import { docsUrl } from '@pnpm/cli-utils'
import { PnpmError } from '@pnpm/error'
import renderHelp from 'render-help'
import { configGet } from './configGet'
import { configSet } from './configSet'
import { configList } from './configList'
import { type ConfigCommandOptions } from './ConfigCommandOptions'
export function rcOptionsTypes () {
return {}
}
export function cliOptionsTypes () {
return {
global: Boolean,
location: ['global', 'project'],
json: Boolean,
}
}
export const commandNames = ['config', 'c']
export function help () {
return renderHelp({
description: 'Manage the pnpm configuration files.',
descriptionLists: [
{
title: 'Commands',
list: [
{
description: 'Set the config key to the value provided',
name: 'set',
},
{
description: 'Print the config value for the provided key',
name: 'get',
},
{
description: 'Remove the config key from the config file',
name: 'delete',
},
{
description: 'Show all the config settings',
name: 'list',
},
],
},
{
title: 'Options',
list: [
{
description: 'Sets the configuration in the global config file',
name: '--global',
shortAlias: '-g',
},
{
description: 'When set to "project", the .npmrc file at the nearest package.json will be used',
name: '--location <project|global>',
},
],
},
],
url: docsUrl('config'),
usages: [
'pnpm config set <key> <value>',
'pnpm config get <key>',
'pnpm config delete <key>',
'pnpm config list',
],
})
}
export async function handler (opts: ConfigCommandOptions, params: string[]) {
if (params.length === 0) {
throw new PnpmError('CONFIG_NO_SUBCOMMAND', 'Please specify the subcommand', {
hint: help(),
})
}
if (opts.location) {
opts.global = opts.location === 'global'
} else if (opts.cliOptions['global'] == null) {
opts.global = true
}
switch (params[0]) {
case 'set': {
let [key, value] = params.slice(1)
if (value == null) {
const parts = key.split('=')
key = parts.shift()!
value = parts.join('=')
}
return configSet(opts, key, value ?? '')
}
case 'get': {
return configGet(opts, params[1])
}
case 'delete': {
return configSet(opts, params[1], null)
}
case 'list': {
return configList(opts)
}
default: {
throw new PnpmError('CONFIG_UNKNOWN_SUBCOMMAND', 'This subcommand is not known')
}
}
}