|
1 | | -import {Command, flags} from '@oclif/command' |
2 | | -import {startServer, AppConfig} from 'json-serverless-lib' |
| 1 | +import { Command, flags } from '@oclif/command'; |
| 2 | +import { startServer, AppConfig } from 'json-serverless-lib'; |
3 | 3 | import express from 'express'; |
4 | 4 | import { Helpers } from '../actions/helpers'; |
5 | 5 |
|
6 | | - |
7 | 6 | export class Run extends Command { |
8 | | - static description = 'describe the command here' |
| 7 | + static description = 'describe the command here'; |
9 | 8 |
|
10 | 9 | static flags = { |
11 | | - help: flags.help({char: 'h'}), |
| 10 | + help: flags.help({ char: 'h' }), |
12 | 11 | // flag with no value (-e, --env) |
13 | 12 | env: flags.string({ |
14 | | - char: 'e', |
15 | | - description: 'environment', // help description for flag |
16 | | - hidden: false, // hide from help |
17 | | - options: ['development', 'local'], |
18 | | - default: 'local', |
19 | | - required: false, |
20 | | - }) |
21 | | - } |
| 13 | + char: 'e', |
| 14 | + description: 'environment', // help description for flag |
| 15 | + hidden: false, // hide from help |
| 16 | + options: ['development', 'local'], |
| 17 | + default: 'local', |
| 18 | + required: false, |
| 19 | + }), |
| 20 | + readonly: flags.boolean({ |
| 21 | + char: 'r', // shorter flag version |
| 22 | + description: 'set api to readonly (true) or writeable (false)', // help description for flag |
| 23 | + hidden: false, // hide from help |
| 24 | + default: false, // default value if flag not passed (can be a function that returns a string or undefined) |
| 25 | + required: false, // default value if flag not passed (can be a function that returns a string or undefined) |
| 26 | + }), |
| 27 | + }; |
22 | 28 |
|
23 | 29 | static args = [ |
24 | 30 | { |
25 | | - name: 'file', // name of arg to show in help and reference with args[name] |
26 | | - required: true, // make the arg required with `required: true` |
| 31 | + name: 'file', // name of arg to show in help and reference with args[name] |
| 32 | + required: true, // make the arg required with `required: true` |
27 | 33 | description: 'path of JSON file', // help description |
28 | | - hidden: false, // hide this arg from help |
29 | | - } |
30 | | - ] |
| 34 | + hidden: false, // hide this arg from help |
| 35 | + }, |
| 36 | + ]; |
31 | 37 |
|
32 | 38 | async run() { |
33 | 39 | await Helpers.generateLogo('json-serverless'); |
34 | 40 | this.log(); |
35 | | - const {args, flags} = this.parse(Run) |
| 41 | + const { args, flags } = this.parse(Run); |
36 | 42 | const server = express(); |
37 | 43 | const defaultConfig = new AppConfig(); |
| 44 | + defaultConfig.readOnly = flags.readonly; |
38 | 45 | defaultConfig.jsonFile = args.file; |
39 | 46 | if (args.file && flags.env) { |
40 | | - startServer(flags.env, server, defaultConfig, this.config.root + '/package.json'); |
| 47 | + startServer( |
| 48 | + flags.env, |
| 49 | + server, |
| 50 | + defaultConfig, |
| 51 | + this.config.root + '/package.json' |
| 52 | + ); |
41 | 53 | } |
42 | 54 | } |
43 | 55 | } |
0 commit comments