conf-cli
- simple cli interface for sindresorhus/conf
- oclif plugin that adds a
confcommand that lets you manage state/configuration between commands- standalone key/value store
Install
npm install -g conf-cli
Requires Node.js 20 or later.
conf [KEY] [VALUE]
manage configuration
USAGE
$ conf [KEY] [VALUE] [-h] [-k <value>] [-v <value>] [-d] [-p <value>] [-n <value>] [-c <value>] [--version]
ARGUMENTS
[KEY] key of the config
[VALUE] value of the config
FLAGS
-c, --cwd=<value> config file location
-d, --delete delete?
-h, --help Show CLI help.
-k, --key=<value> key of the config
-n, --name=<value> config file name
-p, --project=<value> project name
-v, --value=<value> value of the config
--version show conf-cli version
- if [VALUE] is not provided, value of the key is printed (exits with code 1 if the key is not set)
- if [KEY] and [VALUE] is not provided, all the keys will be printed
- keys containing
__proto__,constructororprototypeare rejected--projectand--namecan't contain path separators or..(except a scoped package name like@scope/appfor--project); use--cwdto pick a location
Security note: values are stored as plaintext JSON (under ~/.config/<project>-nodejs/ on Linux by default). Don't store secrets such as passwords or API tokens with conf-cli.
See code: src/commands/conf.ts
Usage
as sindresorhus/conf cli interface
use sindresorhus/conf in your app
// simple-example/index.js
import Conf from 'conf';
const config = new Conf({projectName: 'simple-example'});
console.log(`hello ${config.get('name')}!`);
use conf-cli to update name property from outside the app.
--project/-p flag sets the target project (package name).
$ conf name world -p simple-example
see it affect simple-example
$ node simple-example/index.js
hello world!
as an oclif plugin
create a new oclif project (requires @oclif/core v4 or later)
$ npx oclif generate oclif-example
install conf-cli
$ npm install --save conf-cli
add to oclif plugins in package.json
"oclif": {
"plugins": [
"conf-cli"
]
},
$ oclif-example
VERSION
oclif-example/0.0.0 linux-x64 node-v20.20.2
USAGE
$ oclif-example [COMMAND]
COMMANDS
conf manage configuration <=========== yahoo! ;)
hello Describe the command here
help display help for oclif-example
When used as a plugin, -p will default to the parent cli package name.
$ oclif-example conf name daenarys
$ oclif-example hello
hello daenarys!
$ conf -p oclif-example name
daenarys
// src/commands/hello.js
import {Command} from '@oclif/core'
import Conf from 'conf'
export default class HelloCommand extends Command {
async run() {
const config = new Conf({projectName: this.config.name})
this.log(`hello ${config.get('name')}!`)
}
}
as a standalone key/value store
$ conf hello jonsnow
$ conf hi varys
$ conf hello
jonsnow
$ conf hi
varys
$ conf
hello
hi