/
get.js
27 lines (24 loc) · 826 Bytes
/
get.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const themes = require('../../themes')
const tools = require('../../tools')
const chalk = require('chalk')
const dot = require('dotty')
const noon = require('noon')
const CFILE = `${process.env.HOME}/.leximaven.noon`
exports.command = 'get <key>'
exports.aliases = ['g']
exports.desc = 'Retrieve a config value'
exports.builder = {}
exports.handler = (argv) => {
const key = argv.key
let value = null
tools.checkConfig(CFILE)
const config = noon.load(CFILE)
const theme = themes.loadTheme(config.theme)
if (config.verbose) themes.label(theme, 'down', 'Configuration')
if (dot.exists(config, key)) {
value = /\./i.test(key) ? dot.get(config, key) : config[key]
} else {
throw new Error(`Option ${key} not found.`)
}
console.log(`Option ${chalk.white.bold(key)} is ${chalk.white.bold(value)}.`)
}