MCPcopy
hub / github.com/toddbluhm/env-cmd / parseArgs

Function parseArgs

src/parse-args.ts:9–93  ·  view source on GitHub ↗
(args: string[])

Source from the content-addressed store, hash-verified

7* Parses the arguments passed into the cli
8*/
9export function parseArgs(args: string[]): EnvCmdOptions {
10 // Run the initial arguments through commander in order to determine
11 // which value in the args array is the `command` to execute
12 const program = parseArgsUsingCommander(args)
13
14 const command = program.args[0]
15 // Grab all arguments after the `command` in the args array
16 const commandArgs = args.splice(args.indexOf(command) + 1)
17
18 // Reprocess the args with the command and command arguments removed
19 // program = parseArgsUsingCommander(args.slice(0, args.indexOf(command)))
20
21 const parsedCmdOptions = program.opts()
22 // Set values for provided options
23 let noOverride = false
24 // In commander `no-` negates the original value `override`
25 if (parsedCmdOptions.override === false) {
26 noOverride = true
27 }
28 let useShell = false
29 if (parsedCmdOptions.useShell === true) {
30 useShell = true
31 }
32 let expandEnvs = false
33 if (parsedCmdOptions.expandEnvs === true) {
34 expandEnvs = true
35 }
36 let recursive = false
37 if (parsedCmdOptions.recursive === true) {
38 recursive = true
39 }
40 let verbose = false
41 if (parsedCmdOptions.verbose === true) {
42 verbose = true
43 }
44 let silent = false
45 if (parsedCmdOptions.silent === true) {
46 silent = true
47 }
48
49 let rc: RCFileOptions | undefined
50 if (
51 parsedCmdOptions.environments !== undefined
52 && Array.isArray(parsedCmdOptions.environments)
53 && parsedCmdOptions.environments.length !== 0
54 ) {
55 rc = {
56 environments: parsedCmdOptions.environments,
57 // if we get a boolean value assume not defined
58 filePath: parsedCmdOptions.file === true ?
59 undefined :
60 parsedCmdOptions.file,
61 }
62 }
63
64 let envFile: EnvFileOptions | undefined
65 if (parsedCmdOptions.file !== undefined) {
66 envFile = {

Callers 2

parse-args.spec.tsFile · 0.85
CLIFunction · 0.85

Calls 1

parseArgsUsingCommanderFunction · 0.85

Tested by

no test coverage detected