forked from mwkaufman/noop-local
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·118 lines (112 loc) · 3.5 KB
/
Copy pathcli.js
File metadata and controls
executable file
·118 lines (112 loc) · 3.5 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
#!/usr/bin/env node
const runCommand = require('./lib/commands/run')
const inspectCommand = require('./lib/commands/inspect')
const resetCommand = require('./lib/commands/reset')
const routeCommand = require('./lib/commands/route')
// const connectCommand = require('./lib/commands/connect')
const yargs = require('yargs')
.usage('$0 <command> [options]')
.help('help').alias('help', 'h')
.version('version', `noop-local v${require('./package.json').version}`).alias('version', 'v')
.command('run', 'Run local dev server', (yargs) => {
yargs
.options({
port: {
alias: 'p',
type: 'number',
describe: 'Port bind local dev server',
default: 1234
},
'disable-reload': {
alias: 'd',
type: 'boolean',
description: 'Disable auto-reload for dev server'
},
env: {
alias: 'e',
type: 'array',
description: 'Runtime environment variable(s)'
},
'env-file': {
alias: 'f',
type: 'array',
description: 'Specify paths to environment variable file(s)'
},
component: {
alias: 'c',
type: 'array',
description: 'Name of component(s) to run'
},
resource: {
alias: 'r',
type: 'array',
description: 'Name of resource(s) to run'
},
'router-logging': {
alias: 'l',
type: 'boolean',
describe: 'Output global router logs'
},
})
}, (argv) => {
runCommand(argv)
})
.command('inspect [type..]', 'Inspect Noop app', (yargs) => {
yargs
.positional('type', {
describe: 'Type(s) to inspect (noopfiles, components, resources, routes)'
})
}, (argv) => {
inspectCommand(argv)
})
.command('reset [resource]', 'Reset state of resource', (yargs) => {
yargs
.positional('resource', {
describe: 'Name of resource(s) to reset'
})
.demandOption(['resource'], 'Provide \'resource\' argument when using the reset command')
}, (argv) => {
resetCommand(argv)
})
.command('route [path] [method]', 'Evaluate routing of a specific request', (yargs) => {
yargs
.positional('path', {
describe: 'HTTP path for evaluation like /foo/bar',
type: 'string'
})
.positional('method', {
describe: 'HTTP method for evaluation (GET, PUT, POST, DELETE, OPTIONS)',
type: 'string',
default: 'GET'
})
.demandOption(['path'], 'Provide both \'path\' and \'method\' arguments when using the route command')
}, (argv) => {
routeCommand(argv)
})
.options({
'root-path': {
type: 'string',
description: 'Specify root path of app, overrides default usage of git root',
alias: 'R'
},
verbose: {
type: 'boolean',
description: 'Run with verbose logging'
}
})
.demandCommand(1, 'You need at least one command before moving on')
.strictOptions()
const commands = yargs.getCommandInstance().getCommands()
const argv = yargs.argv
if (!commands.includes(argv._[0])) {
yargs.showHelp()
console.log(`\nUnknown command: ${argv._[0]}`)
}
if (argv.verbose || process.env.DEBUG === 'true') console.log('CLI arguments:', argv)
// .command('connect [resourceId]', 'connect to platform managed resource', (yargs) => {
// yargs.positional('resourceId', {
// describe: 'ID of the resources you\'d like to directly connect to'
// })
// }, (argv) => {
// connectCommand(argv)
// })