climate
builder

builder

configurate

Automatically create many of the fundamentals needed to build robust CLI tools, including help text.

Usage

import { fork } from 'fluture'
import stripAnsi from 'strip-ansi'
 
const YARGS_CONFIG = {
  alias: {
    meal: ['m'],
    happyHour: ['h'],
    multiplier: ['x'],
  },
  boolean: ['happyHour'],
  number: ['multiplier'],
  configuration: {
    'strip-aliased': true,
  },
}
 
const HELP_CONFIG = {
  help: 'This text!',
  // optional
  color: 'Render stuff in color',
  meal: 'Pass the name of the meal you want',
  happyHour: 'Does happy hour apply here?',
  multiplier: 'How many units should we apply?'
}
 
const CONFIG_DEFAULTS = {
  color: true,
  happyHour: false
}
 
const parseArgs = (args) => configurate(
  YARGS_CONFIG,
  // closured so that we can pass cwd at runtime
  {...CONFIG_DEFAULTS, cwd: process.cwd() },
  HELP_CONFIG,
  { name: "dumbwaiter", description: "order food!" },
  // process.argv.slice(2)
  args
)
 
// renders in the failure channel
fork(x => {
  expect(stripAnsi(x).split('\n')).toEqual([
    " dumbwaiter ",
    "",
    "order food!",
    "",
    "  -m / --meal",
    "  	Pass the name of the meal you want",
    "",
    "  -h / --happyHour",
    "  	Does happy hour apply here?",
    "",
    "  -x / --multiplier",
    "  	How many units should we apply?",
    "",
    "  -h / --help",
    "  	This text!",
  ])
  done()
})(done)(
  parseArgs(['--help'])
)

defaultNameTemplate

The default search space when running configFileWithCancel.

Usage

expect(defaultNameTemplate('cool')).toEqual(['.coolrc', '.coolrc.json'])

See also

  • configFileWithCancel

Tools for Monorepos