1.0.3 • Published 1 year ago

@coder-ka/redargs v1.0.3

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

redargs

redargs is a minimal CLI arguments parser.

Installation

npm install redargs

Usage

  • "-" is default flag name before some flag specified.
import { reduceArgs } from 'redargs';

// cli build --dist=dist -b

const parsed = reduceArgs<{
  operation?: string;
  dist: string;
}>(
  process.argv.slice(2),
  (parsed, flag) => {
    switch (flag.name) {
      case "-":
        return {
          ...parsed,
          operation: flag.values[0],
        };
      case "-d": // This is a way to define alias -d for --dist.
      case "--dist":
        return {
          ...parsed,
          dist: flag.values[0],
        };
      default:
        return parsed;
    }
  },
  {
    dist: 'dist'
  }
);

console.log(parsed);
// Output: { operation: 'build', dist: 'dist' }
1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago