0.0.10 • Published 4 years ago

@single-sign-on/cli-tools v0.0.10

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

@single-sign-on/cli-tools

npm i @single-sign-on/cli-tools

Usage

import { buildCli, describe, withFlags } from '@single-sign-on/cli-tools'

/**
 * Specify a function that takes a single object
 * as a parameter. You can assume the keys of
 * this object parameter if you use the 'withFlags'
 * function (see below)
 */
const fn = async ({ argA, argB }) => {
  await new Promise(res => setTimeout(res, 2000))
  return { argA, argB }
}

/**
 * Specify what flags that function should be passed
 *
 * keys with values that are other keys are treated as
 * aliases (aliases can ONLY be single letters)
 */
const fnWithFlags = withFlags(
  fn,
  {
    argA: String,
    argB: Number,
    a: 'argA',
    b: 'argB'
  }
)

/**
 * Describe the function
 *
 * This is used to output helpful
 * CLI documentation
 */
const describedFn = describe(
  fnWithFlags,
  {
    title: 'Some title',
    description: 'Some description'
  }
)

// Build the CLI
const cli = describe({
  fn: describedFn, // <cli> fn -a something -b 42

  // Sub-commands
  subcommand: describe({
    cmd: describe(withFlags(({flag}) => ({ cmd }), { flag: String, f: 'flag' }), { ... }) // <cli> cmd --flag Hello!
  },
  {
    title: 'Some sub-command',
    description: 'Some description'
  })
}, {
  title: 'Some title',
  description: 'Some description'
})
0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.1

4 years ago