Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit a16c5ee

Browse files
author
uid10804
committed
feat(cli): add readonly mode for local run option
1 parent 942a38a commit a16c5ee

File tree

1 file changed

+32
-20
lines changed
  • packages/cli/src/commands

1 file changed

+32
-20
lines changed

packages/cli/src/commands/run.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
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';
33
import express from 'express';
44
import { Helpers } from '../actions/helpers';
55

6-
76
export class Run extends Command {
8-
static description = 'describe the command here'
7+
static description = 'describe the command here';
98

109
static flags = {
11-
help: flags.help({char: 'h'}),
10+
help: flags.help({ char: 'h' }),
1211
// flag with no value (-e, --env)
1312
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+
};
2228

2329
static args = [
2430
{
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`
2733
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+
];
3137

3238
async run() {
3339
await Helpers.generateLogo('json-serverless');
3440
this.log();
35-
const {args, flags} = this.parse(Run)
41+
const { args, flags } = this.parse(Run);
3642
const server = express();
3743
const defaultConfig = new AppConfig();
44+
defaultConfig.readOnly = flags.readonly;
3845
defaultConfig.jsonFile = args.file;
3946
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+
);
4153
}
4254
}
4355
}

0 commit comments

Comments
 (0)