{{#block "logo"}}{{/block}} ## Usage Create a [parser](#parser) function that works like [yargs-parser][] or [minimist][] and handles [creating](#create-a-macro), [using](#use-a-macro), and [removing](#delete-a-macro) macros through command line arguments. ```js var macros = require('{%= name %}'); var parser = macros('macro-store'); var args = parser(process.argv.slice(2)); //=> { _: ['foo', 'bar', 'baz'], verbose: true, cwd: 'qux', isMacro: 'qux' } ``` The returned `args` object also contains the [store methods](#store-1) to give implementors direct access to [setting](#set), [getting](#get), and [deleting](#del) macros in the store. ```js args.set('foo', ['bar', 'baz', 'bang']); args.get('foo'); //=> ['bar', 'baz', 'bang'] ``` ## CLI examples The following examples are using the [example file](example.js) run at the command line with `node example.js`. The objects returned may be used in implementing applications however they choose. Jump to [the API documentation](#api) for implementation information. ### Create a macro The following shows creating a simple macro called `foo`. ![image](https://raw.githubusercontent.com/doowb/macro-store/master/docs/set-simple-macro.png) ### Use a macro The following shows using the `foo` macro, and that the resulting `args` object contains the expanded value. ![image](https://raw.githubusercontent.com/doowb/macro-store/master/docs/get-simple-macro.png) ### Create a complex macro The following shows creating a complex macro called `qux` that includes options `--verbose` and `--cwd boop`. ![image](https://raw.githubusercontent.com/doowb/macro-store/master/docs/set-complex-macro.png) ### Using a complex macro The following shows that using a complex macro is the same as a simple macro, but the `args` object contains the options `verbose: true` and `cwd: 'boop'`, which were set when creating the `qux` macro. ![image](https://raw.githubusercontent.com/doowb/macro-store/master/docs/get-complex-macro.png) ### Delete a macro The following shows how to delete the macro `foo`. This only deletes `foo` and shows that `qux` is still set. ![image](https://raw.githubusercontent.com/doowb/macro-store/master/docs/delete-macro.png) ### Deleting all macros The following shows how to delete all macros. This shows that `foo` and `qux` have been deleted so the `args` object will contain the exact values passed in from the command line. ![image](https://raw.githubusercontent.com/doowb/macro-store/master/docs/delete-all-macros.png) ## API {%= apidocs("index.js") %} {%= apidocs("lib/store.js") %} ## Release history ### key Changelog entries are classified using the following labels _(from [keep-a-changelog][]_): - `added`: for new features - `changed`: for changes in existing functionality - `deprecated`: for once-stable features removed in upcoming releases - `removed`: for deprecated features removed in this release - `fixed`: for any bug fixes Custom labels used in this changelog: * `dependencies`: bumps dependencies * `housekeeping`: code re-organization, minor edits, or other changes that don't fit in one of the other categories. ### v0.3.0 **changed** - refactored parser to return an `args` object similar to [yargs-parser][] and [minimist][] - handles `--macro` option for creating, getting, and removing macros from the `args` object. ### v0.2.0 **changed** - refactored to export a function that creates a parser function. - the parser function returns an object with the action taken and the processed arguments. [keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog