Skip to content

Commit d63b727

Browse files
authored
Merge pull request #12 from Flagsmith/chores/prettify_option
Add prettify option
2 parents a5320d4 + b59f7a8 commit d63b727

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
node_modules
1010
oclif.manifest.json
1111
.idea
12+
flagsmith.json

README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ The steps to using this to provide default flags are as follows. An example of t
1515

1616
1. Install the cli ``npm i flagsmith-cli --save-dev``
1717
2. Call the cli as part of postinstall to create a ``flagsmith.json`` file:
18-
```
19-
"postinstall":"flagsmith get <ENV_API_KEY>"
20-
```
21-
or
18+
2219
```export FLAGSMITH_ENVIRONMENT=API_KEY```
2320

2421
```
@@ -56,7 +53,7 @@ $ npm install -g flagsmith-cli
5653
$ flagsmith COMMAND
5754
running command...
5855
$ flagsmith (--version)
59-
flagsmith-cli/0.1.0 darwin-x64 node-v16.15.1
56+
flagsmith-cli/0.1.2 darwin-arm64 node-v18.13.0
6057
$ flagsmith --help [COMMAND]
6158
USAGE
6259
$ flagsmith COMMAND
@@ -66,7 +63,7 @@ USAGE
6663
# Commands
6764
<!-- commands -->
6865
* [`flagsmith get [ENVIRONMENT]`](#flagsmith-get-environment)
69-
* [`flagsmith help [COMMAND]`](#flagsmith-help-command)
66+
* [`flagsmith help [COMMANDS]`](#flagsmith-help-commands)
7067
* [`flagsmith plugins`](#flagsmith-plugins)
7168
* [`flagsmith plugins:install PLUGIN...`](#flagsmith-pluginsinstall-plugin)
7269
* [`flagsmith plugins:inspect PLUGIN...`](#flagsmith-pluginsinspect-plugin)
@@ -83,14 +80,15 @@ Retrieve flagsmith features from the Flagsmith API and output them to a file.
8380

8481
```
8582
USAGE
86-
$ flagsmith get [ENVIRONMENT] [-o <value>] [-a <value>]
83+
$ flagsmith get [ENVIRONMENT] [-o <value>] [-a <value>] [-i <value>]
8784
8885
ARGUMENTS
8986
ENVIRONMENT The flagsmith environment key to use, defaults to the environment variable FLAGSMITH_ENVIRONMENT
9087
9188
FLAGS
92-
-a, --api=<value> The API URL to fetch the feature flags from
93-
-o, --output=<value> [default: ./flagsmith.json] The file path output
89+
-a, --api=<value> The API URL to fetch the feature flags from
90+
-i, --identity=<value> The identity for which to fetch feature flags
91+
-o, --output=<value> [default: ./flagsmith.json] The file path output
9492
9593
DESCRIPTION
9694
Retrieve flagsmith features from the Flagsmith API and output them to a file.
@@ -107,18 +105,18 @@ EXAMPLES
107105
$ flagsmith get --i flagsmith_identity
108106
```
109107

110-
_See code: [dist/commands/get/index.ts](https://github.com/Flagsmith/flagsmith-cli/blob/v0.1.0/dist/commands/get/index.ts)_
108+
_See code: [dist/commands/get/index.ts](https://github.com/Flagsmith/flagsmith-cli/blob/v0.1.2/dist/commands/get/index.ts)_
111109

112-
## `flagsmith help [COMMAND]`
110+
## `flagsmith help [COMMANDS]`
113111

114112
Display help for flagsmith.
115113

116114
```
117115
USAGE
118-
$ flagsmith help [COMMAND] [-n]
116+
$ flagsmith help [COMMANDS] [-n]
119117
120118
ARGUMENTS
121-
COMMAND Command to show help for.
119+
COMMANDS Command to show help for.
122120
123121
FLAGS
124122
-n, --nested-commands Include all nested commands in the output.
@@ -127,7 +125,7 @@ DESCRIPTION
127125
Display help for flagsmith.
128126
```
129127

130-
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.1.12/src/commands/help.ts)_
128+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.5/src/commands/help.ts)_
131129

132130
## `flagsmith plugins`
133131

@@ -147,7 +145,7 @@ EXAMPLES
147145
$ flagsmith plugins
148146
```
149147

150-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.1.0/src/commands/plugins/index.ts)_
148+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.3.2/src/commands/plugins/index.ts)_
151149

152150
## `flagsmith plugins:install PLUGIN...`
153151

@@ -167,7 +165,6 @@ FLAGS
167165
168166
DESCRIPTION
169167
Installs a plugin into the CLI.
170-
171168
Can be installed from npm or a git url.
172169
173170
Installation of a user-installed plugin will override a core plugin.
@@ -176,6 +173,7 @@ DESCRIPTION
176173
will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
177174
the CLI without the need to patch and update the whole CLI.
178175
176+
179177
ALIASES
180178
$ flagsmith plugins add
181179
@@ -202,6 +200,9 @@ FLAGS
202200
-h, --help Show CLI help.
203201
-v, --verbose
204202
203+
GLOBAL FLAGS
204+
--json Format output as json.
205+
205206
DESCRIPTION
206207
Displays installation properties of a plugin.
207208
@@ -227,7 +228,6 @@ FLAGS
227228
228229
DESCRIPTION
229230
Installs a plugin into the CLI.
230-
231231
Can be installed from npm or a git url.
232232
233233
Installation of a user-installed plugin will override a core plugin.
@@ -236,6 +236,7 @@ DESCRIPTION
236236
will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
237237
the CLI without the need to patch and update the whole CLI.
238238
239+
239240
ALIASES
240241
$ flagsmith plugins add
241242
@@ -264,12 +265,12 @@ FLAGS
264265
265266
DESCRIPTION
266267
Links a plugin into the CLI for development.
267-
268268
Installation of a linked plugin will override a user-installed or core plugin.
269269
270270
e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello'
271271
command will override the user-installed or core plugin implementation. This is useful for development work.
272272
273+
273274
EXAMPLES
274275
$ flagsmith plugins:link myplugin
275276
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flagsmith-cli",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "A CLI allowing you to fetch Flagsmith flags and output them to a file",
55
"author": "kyle-ssg @kyle-ssg",
66
"bin": {

src/commands/get/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command, Flags } from '@oclif/core'
1+
import {Command, Flags} from '@oclif/core'
22
import fetch from 'node-fetch'
33
import flagsmith from 'flagsmith/isomorphic'
44
const fs = require('fs')
@@ -7,10 +7,10 @@ export default class FlagsmithGet extends Command {
77

88
static examples = [
99
'$ FLAGSMITH_ENVIRONMENT=x flagsmith get',
10-
'$ flagsmith get <ENVIRONMENT_ID>',
1110
'$ flagsmith get --o ./my-file.json',
1211
'$ flagsmith get --a https://flagsmith.example.com/api/v1/',
1312
'$ flagsmith get --i flagsmith_identity',
13+
'$ flagsmith get -p',
1414
]
1515

1616
static flags = {
@@ -23,6 +23,9 @@ export default class FlagsmithGet extends Command {
2323
identity: Flags.string({
2424
char: 'i', description: 'The identity for which to fetch feature flags', required: false,
2525
}),
26+
pretty: Flags.boolean({
27+
char: 'p', description: 'Prettify the output JSON', required: false, default: true,
28+
}),
2629
}
2730

2831
static args = [
@@ -32,17 +35,19 @@ export default class FlagsmithGet extends Command {
3235
]
3336

3437
async run(): Promise<void> {
35-
const { args, flags } = await this.parse(FlagsmithGet)
38+
const {args, flags} = await this.parse(FlagsmithGet)
3639
const environment = args.environment || process.env.FLAGSMITH_ENVIRONMENT
3740
const api = flags.api || process.env.FLAGSMITH_ENVIRONMENT
3841
if (!environment) {
3942
this.log('A flagsmith environment was not specified, run flagsmith get --help for more usage.')
4043
}
41-
const identity = flags.identity;
44+
45+
const identity = flags.identity
4246
let outputString = `Flagsmith: Retrieving flags from ${environment}`
4347
if (identity) {
4448
outputString += ` for identity ${identity}`
4549
}
50+
4651
const output = flags.output
4752
outputString += `, outputing to ${output}.`
4853
this.log(outputString)
@@ -53,6 +58,10 @@ export default class FlagsmithGet extends Command {
5358
api: api,
5459
identity: identity,
5560
})
56-
fs.writeFileSync(output, JSON.stringify(flagsmith.getState()))
61+
if (flags.pretty) {
62+
fs.writeFileSync(output, JSON.stringify(flagsmith.getState(), null, 2))
63+
} else {
64+
fs.writeFileSync(output, JSON.stringify(flagsmith.getState()))
65+
}
5766
}
5867
}

0 commit comments

Comments
 (0)