-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathargs.ts
More file actions
186 lines (177 loc) · 5.74 KB
/
args.ts
File metadata and controls
186 lines (177 loc) · 5.74 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import yargs from 'yargs';
import { Config } from './types';
type SharedParams = {
proxy_url?: string;
debug?: boolean;
config_file?: string;
env?: boolean;
secret?: string;
base_path?: string; // Necessary when package imported as Node module
config?: Partial<Config>;
experimental_ea?: boolean;
};
export type DryRunMode = 'preview';
type ImportSpecificParams = {
input_file: string;
dry_run?: boolean | '' | DryRunMode;
interactive?: boolean;
apply?: boolean;
};
type ExportSpecificParams = {
format: 'yaml' | 'directory';
output_folder: string;
export_ids?: boolean;
export_ordered?: boolean;
};
export type ExportParams = ExportSpecificParams & SharedParams;
export type ImportParams = ImportSpecificParams & SharedParams;
export type CliParams = (ExportParams | ImportParams) & {
_: ['export' | 'import' | 'deploy' | 'dump'];
};
function getParams(): CliParams {
const args = yargs
.demandCommand(1, 'A command is required')
.usage('Auth0 Deploy CLI')
.option('debug', {
alias: 'd',
describe: 'Dump extra debug information.',
type: 'boolean',
default: false,
})
.option('proxy_url', {
alias: 'p',
describe: 'A url for proxying requests, only set this if you are behind a proxy.',
type: 'string',
})
.option('experimental_ea', {
describe: 'This will enable supoort experimental early access of features/resource types.',
type: 'boolean',
default: false,
})
.command(['import', 'deploy'], 'Deploy Configuration', {
input_file: {
alias: 'i',
describe:
'The updates to deploy. Either a JSON file, or directory that contains the correct file layout. See README and online for more info.',
type: 'string',
demandOption: true,
},
config_file: {
alias: 'c',
describe: 'The JSON configuration file.',
type: 'string',
},
env: {
describe: 'Override the mappings in config with environment variables.',
boolean: true,
default: true,
},
secret: {
alias: 'x',
describe:
'The client secret, this allows you to encrypt the secret in your build configuration instead of storing it in a config file',
type: 'string',
},
dry_run: {
alias: 'dry-run',
describe:
'Dry-run mode. Show plan without applying changes. Use --interactive for the menu or --apply to show the plan and apply without prompting.',
type: 'string',
},
interactive: {
describe:
'Use with --dry-run to enable the interactive menu (apply / export to file / exit). Not available in non-TTY environments.',
type: 'boolean',
default: false,
},
apply: {
describe: 'Use with --dry-run to show the plan and then apply without prompting.',
type: 'boolean',
default: false,
},
})
.command(['export', 'dump'], 'Export Auth0 Tenant Configuration', {
output_folder: {
alias: 'o',
describe: 'The output directory.',
type: 'string',
demandOption: true,
},
format: {
alias: 'f',
describe: 'The output format.',
type: 'string',
choices: ['yaml', 'directory'],
demandOption: true,
},
config_file: {
alias: 'c',
describe: 'The JSON configuration file.',
type: 'string',
},
secret: {
alias: 'x',
describe:
'The client secret, this allows you to encrypt the secret in your build configuration instead of storing it in a config file',
type: 'string',
},
env: {
describe: 'Override the mappings in config with environment variables.',
boolean: true,
default: true,
},
export_ids: {
alias: 'e',
describe: 'Export identifier field for each object type.',
type: 'boolean',
default: false,
},
export_ordered: {
alias: 's',
describe: 'Order keys in exported JSON files for consistent diffs.',
type: 'boolean',
},
})
.example(
'$0 export -c config.json -f yaml -o path/to/export',
'Dump Auth0 config to folder in YAML format'
)
.example(
'$0 export -c config.json -f directory -o path/to/export',
'Dump Auth0 config to folder in directory format'
)
.example('$0 import -c config.json -i tenant.yaml', 'Deploy Auth0 via YAML')
.example('$0 import -c config.json -i path/to/files', 'Deploy Auth0 via Path')
.example(
'$0 import -c config.json -i tenant.yaml --dry-run',
'Preview changes and exit without applying changes'
)
.example(
'$0 import -c config.json -i tenant.yaml --dry-run --apply',
'Show plan and apply without prompting (CI deployment)'
)
.example(
'$0 import -c config.json -i tenant.yaml --dry-run --interactive',
'Show plan with interactive menu (apply / export / exit)'
)
.example(
'$0 dump -c config.json -f yaml -o path/to/export',
'Dump Auth0 config to folder in YAML format'
)
.example(
'$0 dump -c config.json -f directory -o path/to/export',
'Dump Auth0 config to folder in directory format'
)
.example('$0 deploy -c config.json -i tenant.yaml', 'Deploy Auth0 via YAML')
.example('$0 deploy -c config.json -i path/to/files', 'Deploy Auth0 via Path')
.epilogue(
'See README (https://github.com/auth0/auth0-deploy-cli) for more in-depth information on configuration and setup.'
)
.wrap(null);
//@ts-ignore because we know these types are either ExportParams or ImportParams. TODO: fix more native way of inferring types from yargs
return args.argv;
}
export default {
getParams,
};
export { getParams };