meow-reverse

0.2.1 • Public • Published

meow-reverse ci nycrc config on GitHub

Generate arguments that would produce the given input and flags in accordance to meow options.

Install

npm install --save-dev meow-reverse

Usage

import meowrev from 'meow-reverse';

const options = {
  importMeta: import.meta,
  flags: {
    rainbow: {
      type: 'boolean',
      alias: 'r'
    }
  }
};
const cli = {
  input: [ 'unicorns' ],
  flags: { rainbow: true },
};

const argv = meowrev(cli, options);
console.log(argv);

Output:

[ 'unicorns', '--rainbow' ]

Since meow does not provide a function that simply parses arguments, meowparse is available for this purpose:

import { meowparse } from 'meow-reverse';

const options = {
  importMeta: import.meta,
  flags: {
    rainbow: {
      type: 'boolean',
      alias: 'r'
    }
  }
};

const argv = [ 'unicorns', '-r' ];
const { input, flags } = meowparse(argv, options);
console.log(input, flags);

Output:

[ 'unicorns' ] { rainbow: true }

meowparse can only handle common use cases. It does not support, for instance, returning of unknown flags.

Notes

The function will throw when a flag is incompatible with the options given. For instance, any flag that has a default value must be present. This applies to all boolean flags, as they have an implicit default value of false.

Flags are omitted when their values match their default.

Short aliases are employed for multi-value flags. The following:

const options = {
  importMeta: import.meta,
  flags: {
    file: {
      type: 'string',
      alias: 'f'
    }
  }
};
const cli = {
  input: [ 'show' ],
  flags: { file: [ 'meow.gif', 'woof.gif' ] },
};

const argv = meowrev(cli, options);

Will produce:

[ 'show', '-f', 'meow.gif', '-f', 'woof.gif' ]

Use a package like shell-quote to convert the array outputted by the function into an actual command-line.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.2.1
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.2.1
    2
  • 0.2.0
    0
  • 0.1.0
    0

Package Sidebar

Install

npm i meow-reverse

Weekly Downloads

2

Version

0.2.1

License

MIT

Unpacked Size

823 kB

Total Files

8

Last publish

Collaborators

  • cleong