JSPM

config-cli-helper

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 35
  • Score
    100M100P100Q50522F
  • License ISC

config-cli-helper

Package Exports

  • config-cli-helper
  • config-cli-helper/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (config-cli-helper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

config-cli-helper

Helper for quickly writing commands such as npm config lsnpm config getnpm config set ...

cmd list:

  • you-cli config -h
  • you-cli config set <key>=<value> [<key>=<value> ...]
  • you-cli config get [<key> [<key> ...]]
  • you-cli config del <key> [<key> ...]
  • you-cli config ls [--json]
  • you-cli config reset

install

npm i config-cli-helper or yarn add config-cli-helper

use

import cac from 'cac';
import { getConfigStore, getConfigCli, cacHelpWithConfigCli, ParamsDescription } from 'config-cli-helper';

const cliName = 'you-cli';
const defaultConfigStore = {
  config: {
    cwd: './',
  },
};
const paramsDescription: ParamsDescription = [
  { key: 'cwd'; value: string; description: string; },
];
const configStore = getConfigStore(cliName, defaultConfigStore);

// For example, this cmd: `you-cli config ls`
if (process.argv[2] === 'config') {
  const configCli = getConfigCli({
    cliName,
    configStore, // If you want to customize 'configStore', you can pass in this parameter. Otherwise, it will generate a "configStore" for you by default
    paramsDescription,
  });
  configCli.parse(process.argv.slice(1));
  process.exit();
}

console.log('config: ', configStore.get('config')); // { cwd: './' }

// Other cmd. For example, this cmd: `you-cli -h`
const cli = cac(cliName);
cli.help(
  cacHelpWithConfigCli(cliName)
);