config-or-ask
v1.1.2
Published
CLI that stores values in a config and can be called in bash scripts. If the value is not in the config, then it'll look in your environment variables and if it's not there, it'll ask the user for input. It's a form of caching information for use in bash
Downloads
6
Maintainers
Readme
config-or-ask
This is a CLI that helps you get values in your bash scripts. The way it works is that it looks to see if the variable name you're looking for is in a file or in the environment and if it is there then it returns that value. If the value is not there, then it asks the user for input and then stores that for future use.
Quick Installation
npm install -g config-or-ask
Full Installation
In order to provide this CLI to all users, we'll want to install it from the binaries provided. Download the .tar.gz
file from the releases page.
Then run the following to install:
tar -xvf config-or-ask-<version>.tar.gz
sudo rm -rf /usr/local/src/config-or-ask
sudo rm -rf /usr/local/bin/config-or-ask
sudo mv config-or-ask /usr/local/src/config-or-ask
sudo ln -s /usr/local/src/config-or-ask/bin/config-or-ask /usr/local/bin/config-or-ask
Usage
The idea for this CLI is that you use it in a bash script to retrieve values from a cache if you have it or from user input if you don't. Examples may include:
USERNAME=$(config-or-ask get MY_APP_USERNAME)
# This will check if the variable MY_APP_USERNAME exists
# in the config or in the environment. If it is not there
# it will ask the user to input a value for it. Let's say
# that the value wasn't there and the user enters "bob".
echo ${USERNAME}
# Output: bob
# You can also have custom config locations. For example
# you may wan't project level configs. In that case, you
# can use the --config flag to specify a config file.
USERNAME=$(config-or-ask get MY_APP_USERNAME --config=./path/to/my/config.json)
# It will automatically create that folder path and
# config file if it doesn't exist.
# Finally, there may be times when you don't want to
# use the environment variables. In that case you
# can use the --skip-env flag.
USERNAME=$(config-or-ask get MY_APP_USERNAME --skip-env)
Here's how you use the CLI:
$ npm install -g config-or-ask
$ config-or-ask COMMAND
running command...
$ config-or-ask (--version)
config-or-ask/1.1.2 linux-x64 node-v16.15.0
$ config-or-ask --help [COMMAND]
USAGE
$ config-or-ask COMMAND
...
Commands
config-or-ask delete VARIABLE
Adds the ability to delete a variable from the config
USAGE
$ config-or-ask delete [VARIABLE] [-p <value>]
ARGUMENTS
VARIABLE The name of the variable you would like to get
FLAGS
-p, --config=<value> Path to config file (not required, we use one from your local home directory if you do not
specify one)
DESCRIPTION
Adds the ability to delete a variable from the config
EXAMPLES
$ config-or-ask delete
See code: dist/commands/delete.ts
config-or-ask get VARIABLE
Gets the variable you are looking for from the config file or environment. If it cannot find a value, it asks you for it. You're able to disable the environment or config files if you don't want it to use those.
USAGE
$ config-or-ask get [VARIABLE] [-e] [-c] [-p <value>]
ARGUMENTS
VARIABLE The name of the variable you would like to get
FLAGS
-c, --skip-config Don't look at config file for the value
-e, --skip-env Don't look at environment variables for the value
-p, --config=<value> Path to config file (not required, we use one from your local home directory if you do not
specify one)
DESCRIPTION
Gets the variable you are looking for from the config file or environment. If it cannot find a value, it asks you for
it. You're able to disable the environment or config files if you don't want it to use those.
If the config does not exist, it will create it for you.
The order of importance is:
1. Config file
2. Environment variable
3. User input
EXAMPLES
$ config-or-ask get MY_VARIABLE_NAME
$ config-or-ask get MY_VARIABLE_NAME --skip-env
$ config-or-ask get MY_VARIABLE_NAME --skip-config
$ config-or-ask get MY_VARIABLE_NAME --config=./path/to/config.json
MY_VARIABLE_NAME=$(config-or-ask get MY_VARIABLE_NAME)
See code: dist/commands/get.ts
config-or-ask help [COMMAND]
Display help for config-or-ask.
USAGE
$ config-or-ask help [COMMAND] [-n]
ARGUMENTS
COMMAND Command to show help for.
FLAGS
-n, --nested-commands Include all nested commands in the output.
DESCRIPTION
Display help for config-or-ask.
See code: @oclif/plugin-help