Git Product home page Git Product logo

aio-cli-config's Introduction

aio-cli-config

oclif Version Downloads/week Build Status License Greenkeeper badge Codecov Coverage

This is a nodejs module to allow management of persistant and environment variable configuration by aio-cli plugins.

The module can be added to your project with:

> yarn add aio-cli-config

or

> npm install aio-cli-config --save

Here is a snippet:

const config = require('aio-cli-config')

// set a key value
config.set('pgb.authtoken', 1234)

// reload data from files and environmental variables
config.reload()

// get all stored data
config.get()

// get data from a given key
config.get('pgb.authtoken')

// delete a key
config.delete('pgb.authtoken')

Peristent File Locations

User Configuration

The user default location is:

  1. ENV['AIO_CONFIG_FILE']
  2. ENV['XDG_CONFIG_HOME']/aio
  3. <HOME>/.config/aio

depending on whether the specified environmental variables exist

Project Configuration

Local configuration is loaded from $PWD/.aio

Dot Env Configuration

A local .env file is also loaded. This file can contain environmental variables

Resolving Values

Resolving configuration is done in two steps:

  1. .env file is read, parsed and hoisted to environment variables ( process.env )
  2. user and local files are read

Inheritance is similar to NPMRC and can be set using user file, project file and matching environment variables. Values are read and merged in the following order in increasing priority:

  1. user config eg. ~/.config/aio
  2. project config eg. $PWD/.aio
  3. environment variables matching AIO_<PLUGIN>_<KEY>
$ AIO_PGB_AUTHTOKEN=1234 node
> config.get('pgb.authtoken')
1234

$ AIO_PGB_AUTH__TOKEN=1234 node # use double underscores to specify an underscore
> config.get('pgb.auth_token')
1234

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

aio-cli-config's People

Contributors

goya avatar purplecabbage avatar shazron avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aio-cli-config's Issues

ACNA-337 - Reloading doesn't reload dotenv

Describe the bug
write a .env, load config, rewrite .env, reload => same config as in first load

The issue is within dotenv where process.env vars have prio over the .env file, meaning that once a .env file is loaded to process.env, we cannot override:
See motdotla/dotenv#122

Expected behavior
Not sure here, do we want to/ can we support env variable reload?

ACNA-364 - incorrect `config --verbose` output for global configuration

Expected Behaviour

With the --verbose config flag, it should show the correct global configuration value.

Actual Behaviour

With the --verbose configuration flag, it shows the local configuration value as a global configuration value.

Steps to Reproduce

1. aio config:set foo.bar abc123
2. aio config --verbose
3. echo "{ 
  foo: 
 {  
    bar: baz 
 } 
}" > .aio
4. aio config --verbose

At the start, the config looks like this:

---- Global configuration: /Users/shazron/.config/aio
---- Local configuration: /Users/shazron/Documents/git/adobe/.aio
---- Environmental Variables
---- Active Configuration

At Step 2, it looks like this:

---- Global configuration: /Users/shazron/.config/aio
{
  foo: {
    bar: "abc123"
  }
}
---- Local configuration: /Users/shazron/Documents/git/adobe/.aio
---- Environmental Variables
---- Active Configuration
{
  foo: {
    bar: "abc123"
  }
}

At Step 4, it looks like this:

---- Global configuration: /Users/shazron/.config/aio
{
  foo: {
    bar: "baz"
  }
}
---- Local configuration: /Users/shazron/Documents/git/adobe/.aio
{
  foo: {
    bar: "baz"
  }
}
---- Environmental Variables
---- Active Configuration
{
  foo: {
    bar: "baz"
  }
}

Platform and Version

2.0.1-dev.0

merging config values doesnt work if top level is not an object

Expected Behaviour

non-object values should be overridden by subsequent values

Actual Behaviour

if value of a config key is a string it wont get overridden by a non-object value

Steps to Reproduce

aio config set a 12
aio config set -l a.b 12
aio config # should be {a:{b:12}} but is {a:12}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.