{"_id":"flopmang","_rev":"8-9904ff579853aca4836cf2e83e111f18","name":"flopmang","description":"Flag Option Manager for Grunt: framework for converting grunt task-options into CLI flags for child processes","dist-tags":{"latest":"1.0.0"},"versions":{"0.0.0":{"name":"flopmang","version":"0.0.0","description":"Flag Option Manager for Grunt: framework for converting grunt task-options into CLI flags for child processes","main":"lib/argUtil.js","engines":{"node":">= 0.8.0"},"scripts":{"test":"grunt test"},"repository":{"type":"git","url":"https://github.com/dylancwood/flopmang.git"},"keywords":["grunt","tasks","options","arguments","flags","command","line"],"author":{"name":"Dylan Wood","email":"dylancwood@gmail.com","url":"bydywo.blogger.com"},"license":"MIT","bugs":{"url":"https://github.com/dylancwood/flopmang/issues"},"homepage":"https://github.com/dylancwood/flopmang","devDependencies":{"grunt":"~0.4.0","grunt-bump":"0.0.13","grunt-contrib-jshint":"~0.1.1","grunt-contrib-watch":"~0.5.3","grunt-jscs":"~0.6.1","grunt-mocha-cli":"~1.0.1"},"dependencies":{"underscore":"^1.6.0","underscore.string":"^2.3.3"},"gitHead":"363fc1d092f9b87fa174863e4aadb41ed2bc186e","_id":"flopmang@0.0.0","_shasum":"29b38ca036619e5d7cfcfe488a0d076e0d19b6cd","_from":".","_npmVersion":"1.4.20","_npmUser":{"name":"dylancwood","email":"dylancwood@gmail.com"},"maintainers":[{"name":"dylancwood","email":"dylancwood@gmail.com"}],"dist":{"shasum":"29b38ca036619e5d7cfcfe488a0d076e0d19b6cd","tarball":"https://registry.npmjs.org/flopmang/-/flopmang-0.0.0.tgz","integrity":"sha512-Elhmfe/eIdhTOndnbCQpheBAzP4Wc5vIBv9/vw5utEWfQLf83SjQsXvf7e6OjJiF9GAXTKmqjDykShCMPUxt5w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC/voZ1E0zZHg+1oiBOwSFS7rpT1YuSjW0qboy568qUzAIhAK8YjEvtWLQbmYcnCST9r/t1Z0RwB0xSP6j5XkSlshNV"}]},"directories":{}},"0.0.1":{"name":"flopmang","version":"0.0.1","description":"Flag Option Manager for Grunt: framework for converting grunt task-options into CLI flags for child processes","main":"lib/argUtil.js","engines":{"node":">= 0.8.0"},"scripts":{"test":"grunt test"},"repository":{"type":"git","url":"https://github.com/dylancwood/flopmang.git"},"keywords":["grunt","tasks","options","arguments","flags","command","line"],"author":{"name":"Dylan Wood","email":"dylancwood@gmail.com","url":"bydywo.blogger.com"},"license":"MIT","bugs":{"url":"https://github.com/dylancwood/flopmang/issues"},"homepage":"https://github.com/dylancwood/flopmang","devDependencies":{"grunt":"~0.4.0","grunt-bump":"0.0.13","grunt-contrib-jshint":"~0.1.1","grunt-contrib-watch":"~0.5.3","grunt-jscs":"~0.6.1","grunt-mocha-cli":"~1.0.1"},"dependencies":{"underscore":"^1.6.0","underscore.string":"^2.3.3"},"gitHead":"9bb84eef1ea946c453b3ecbd490cc3fc1ee2ceb5","_id":"flopmang@0.0.1","_shasum":"73e4814eeeb94b44b5acfd8206d92756acdfb3e8","_from":".","_npmVersion":"1.4.20","_npmUser":{"name":"dylancwood","email":"dylancwood@gmail.com"},"maintainers":[{"name":"dylancwood","email":"dylancwood@gmail.com"}],"dist":{"shasum":"73e4814eeeb94b44b5acfd8206d92756acdfb3e8","tarball":"https://registry.npmjs.org/flopmang/-/flopmang-0.0.1.tgz","integrity":"sha512-ot08C4fS/ltb+Nh4xMBjDVPVx38zYN22ZJ8AIbpGDJ7+VWqRm/oQhAnUTK3GGdBzl5Jbm/Qt/HXJQQ7hAwS0mg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC4LfywCu+h2eMIxCgBAFm83Lgz15CBUCYHBV46aycAYAIhAKhnNy4rZUlOl2olm2oCYQpvgxs65jv6bhGrW8MqbJq8"}]},"directories":{}},"1.0.0":{"name":"flopmang","version":"1.0.0","description":"Flag Option Manager for Grunt: framework for converting grunt task-options into CLI flags for child processes","main":"lib/argUtil.js","engines":{"node":">= 0.8.0"},"scripts":{"test":"grunt test"},"repository":{"type":"git","url":"git+https://github.com/dylancwood/flopmang.git"},"keywords":["grunt","tasks","options","arguments","flags","command","line"],"author":{"name":"Dylan Wood","email":"dylancwood@gmail.com","url":"bydywo.blogger.com"},"license":"MIT","bugs":{"url":"https://github.com/dylancwood/flopmang/issues"},"homepage":"https://github.com/dylancwood/flopmang","devDependencies":{"grunt":"^1.0.4","grunt-bump":"^0.8.0","grunt-contrib-jshint":"^2.1.0","grunt-contrib-watch":"^1.1.0","grunt-jscs":"^3.0.1","grunt-mocha-cli":"^4.0.0"},"dependencies":{"underscore":"^1.9.1","underscore.string":"^3.3.5"},"gitHead":"2800bf5dff3b0e246cbdb769da61b9b3f136af6e","_id":"flopmang@1.0.0","_shasum":"22c82f12b537d5d440d5f0ad87ac39109ff31e26","_from":".","_npmVersion":"4.6.1","_nodeVersion":"4.9.1","_npmUser":{"name":"dylancwood","email":"dylancwood@gmail.com"},"dist":{"shasum":"22c82f12b537d5d440d5f0ad87ac39109ff31e26","tarball":"https://registry.npmjs.org/flopmang/-/flopmang-1.0.0.tgz","integrity":"sha512-WQsI7/o5g8NC/VCKbAJQcxSm77k1hd5beC0qikWOvz9iDqwKiwB0xfSGIgAOpHck00enCiJKUrzsGN775FQzdw==","fileCount":11,"unpackedSize":35357,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc+/9eCRA9TVsSAnZWagAAR9YP/2/nh2sFeQDWdjeS5LU0\n5aKTK84k78OBSwfIHI1v8c5Z5gMz6oX8PPyaMFSy17YjH8XOdvYS6FFmPkN8\n68cvA70g2DPB83npX081xQrSAMZalN343sAtNfbswAffrnrZ/5s5sFlN5GAT\nb/q+E1pqFQsYDbMSJhAB7qPzWP4PS64daVOYKdFdjjtQtqscvrkTksxs+rE3\nTKQa24hDUMJS9doXAFBnn1Bjv60oOUt79/W3hydOnyaY97VfJd2S0sHTUCv/\nG3E/51ItEdC/NWVFsrMfhUqSC476Ttho1Hd/tu2LI7rLoLhcXjTrD1BlL7dM\nRKy/d6hA0Mad2RyEsRyASPFJNH5XOAaw0t5bpprB+MyjG9fskkWYDKHftUSj\nBAhspQx8iKE9MEI5oU+jt/gnIfGbdtlzoXQhVxrGNoIvHX4JIgIegfKea369\nPhvtHmFKeCQra2AX3fmFc9VQmZq8jmUxCj2XORqPKrWtPF5Fxg2bZit84rWw\nnmNRXyfQXJVuiZPygGmcvbiGuJLBESNS2qLCUBYKcbZTvnFPnxFm3zYQnyvG\nRXAK5daDmRpXBCI+2PpAps25ZATzP/YM3LOKJT+tOgvY+yZXPjAoc91vkkez\nD3d7yxmOL3tbeFwTRXvamlSxPm+XR0OpAYA1sgnC3mGLZ1nKjHheLZT3+5Qw\nq+Vn\r\n=C9j+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCBynGFa9Y5uaeUkbqdwk3d+dIsDYYUAFMCgO0/5iarXQIhAM44gOPzeFg2j6A0U1jZCnXKeT+tJfvOsyGglCtE29v1"}]},"maintainers":[{"name":"dylancwood","email":"dylancwood@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/flopmang_1.0.0_1560018781678_0.7710030699170094"},"_hasShrinkwrap":false}},"readme":"flopmang\n========\n\nFlag-Option Manager for Grunt: framework for converting grunt task-options into CLI flags for child processes\n\n## Getting started\n\n**What this isn't:** this is not a grunt plugin. \n\n**What this is:** a utility to make writing and extending plugins that delegate to command line APIs easier. It provides a simple interface for mapping grunt-task-options to command line flags.\n\n### Installation:\n```shell\nnpm install --save flopmang\n```\n\n```js\nvar ArgUtil = require('flopmang');\n```\n\n### Quick example:\nThe code below illustrates how to set up a simple grunt multiTask that will run `npm install` in any directory you wish. When using configuring the task in the Gruntfile, the user will be able to specify the following options:\n\n* *global* default: `undefined`: translated to `-g` if set to truey\n* *saveDev* default: `undefined`: translated to `--save-dev` by underscore.string.dasherize\n* *dir* default: `process.cwd`: translated to cwd option when spawning child process\n*package* default: `undefined`: **required**. Only the value is appended to the args\n```js\nvar ArgUtil = require('flopmang');\nvar async = require('async');\n\nmodule.exports = function (grunt) {\n    grunt.registerMulitTask(\n        'npmInstall',\n        'runs npm install in any directory'\n        function () {\n            var argConfigs = [\n                {\n                    option: 'global',\n                    flag: '-g'\n                },\n                {\n                    option: 'saveDev',\n                },\n                {\n                    option: 'dir',\n                    defaultValue: process.cwd,\n                    useAsFlag:false,\n                },\n                {\n                    option: 'package',\n                    required: true,\n                    useAsFlag: false,\n                    useValue: true\n                },\n            ];\n            var argUtil = new ArgUtil(this, argConfigs);\n\n            var args = ['npm', 'install'].concat(argUtil.getArgFlags());\n\n            var done = async();\n\n            var options = argUtil.options;\n\n            var spawnOpts = {};\n\n            if (options.dir) {\n                spawnOpts.cwd = options.dir;\n            }\n\n            var cp = grunt.util.spawn({\n                args: args,\n                opts: spawnOpts,\n                function spawnEnd (err, result, code) {\n                    if (err) {\n                        throw err\n                    }\n                    grunt.log.writeln('\\n' + result.stdout);\n                    done();\n                }\n            });\n        }\n    );\n```\nThe `argConfigs` array contains multiple objects that describe options, and how they should be mapped to CLI flags by `getArgFlags()`;\n\nUsing this multitask in a Gruntfile:\n\n```js\ngrunt.initConfig({\n    npmInstall{\n        flopmang: {\n            options: {\n                package: 'flopmang',\n                dir: '/home/dylancwood/project',\n                global: false,\n                saveDev: true\n            }\n        }\n    }\n});\n```\n\n## API\n### argConfig\nThe following properties are available to configure each option/argument:\n\n#### option\nType: `string`\nDefault value: `undefined`\n**Required**\n\nThe name of the option (e.g. 'global' or 'package');\n\n#### customFlagFn\nType: `function`\nDefault value: `undefined`\n\nA function to be used to generate a custom flag value.\nThis function is given one argument: the current arg object.\nThis overrides `useAsFlag`.\nexample:\n```\n...\n{\n    option: 'customOption',\n    customFlagFn: function (arg) {\n        if (arg.value) {\n            return arg.option + '-' + arg.value;\n        }\n        return null;\n    }\n}\n...\n```\n\n#### customValueFn\nType: `function`\nDefault value: `undefined`\n\nA function to be used to generate a custom value string.\nThis function is given one argument: the current arg object.\nThis overrides `useValue`. See above for example.\n\n#### defaultValue\nType: `any`\nDefault value: `undefined`\n\nThe default value for the option if the user does not specify it\n\n#### flag\nType: `string`\nDefault value: `undefined`\n\nIf set, and `useAsFlag` is true, this value will be used as the flag. This is overridden by the value returned by `customFlagFn`.\n\n#### required\nType: `boolean`\nDefault value: `false`\n\nIf set to true, an error will be thrown if the value of the option is `null`, an empty string (`''`), or `undefined`. For more complex validation, see `validationFn`\n\n#### useAsFlag\nType: `boolean`\nDefault value: `true`\n\nIf set to true, then the option label will be included in the flags unless the option's value is a falsy (*excluding zero*). This is overridden by the `customFlagFn`.\n\n#### useDasherize\nType: `boolean`\nDefault value: `true`\n\nIf set to true, then the option label will be prepended with `--` and processed using underscore.string's `dasherize` function. (e.g. `oCamelCase` will be converted to `--o-camel-case`)\n\n#### useValue\nType: `boolean`\nDefault value: `false`\n\nIf set to true, then the value of the option will be included in the flags unless the value is a falsy (*excluding zero*). This is overridden by the `customValueFn`.\n\n#### validationFn\nType: `function`\nDefault value: `undefined`\n\nThe option will be validated using this function. This function may either throw an error, or return false to indicate that the option is invalid. Returning true indicates that the option is valid.\nThis function is given one argument: the current arg object.\nexample:\n```\n...\n{\n    option: 'customOption',\n    validationFn: function (arg) {\n        if (arg.value === undefined) {\n            raise new Error('must provide a ' + arg.option);\n        }\n        if (arg.value > 10 && arg.value < 100) {\n            return true\n        }\n        return false;\n    }\n}\n...\n```\n#### value\nType: `any`\nDefault value: `undefined`\n\nThis should never be used. Though it is possible to set the value here, it will be overridden by the defaultValue before the constructor returns. \n\n### Constructor\n```js\nvar flopmang = new FlOpMang(task, configs);\n```\nThe constructor takes two arguments:\n\n#### task\nType: `object`\n\nThe current grunt task. This is used to extend the default values with the user-provided options at run-time. Depending on the context from which you are calling the constructor, you can use `this`, or `grunt.task.current`.\n\n#### configs\nType: `array`\n\nAn array of argConfig configuration objects as described above.\nExample:\n```js\nvar configs = [\n    { option: 'option1' },\n    { option: 'option2', useValue: true }\n];\nvar flopMang = new FlopMang(grunt.task.current, configs);\n```\n\n### getArgFlags\nThe getArgFlags method returns an array of flags that have been created according to the `configs` and user-specified options. \n\n#### Example:\nSuppose that we have the following `configs`:\n```js\n[\n    { option: 'option1'},\n    { option: 'option2', flag: '-o', defaultValue: true },\n    { option: 'option3', useAsFlag: false, useValue: true }\n]\n```\nAnd suppose that the config for the current task/target looks like this:\n```js\noptions: {\n    option1: true,\n    option3: 100\n}\n```\ngetArgFlags will produce the following output:\n```js\n['--option1', '-o', 100]\n\n```\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n","maintainers":[{"name":"dylancwood","email":"dylancwood@gmail.com"}],"time":{"modified":"2022-06-18T02:16:03.143Z","created":"2014-07-13T04:35:38.181Z","0.0.0":"2014-07-13T04:35:38.181Z","0.0.1":"2014-07-13T06:25:49.093Z","1.0.0":"2019-06-08T18:33:01.812Z"},"homepage":"https://github.com/dylancwood/flopmang","keywords":["grunt","tasks","options","arguments","flags","command","line"],"repository":{"type":"git","url":"git+https://github.com/dylancwood/flopmang.git"},"author":{"name":"Dylan Wood","email":"dylancwood@gmail.com","url":"bydywo.blogger.com"},"bugs":{"url":"https://github.com/dylancwood/flopmang/issues"},"license":"MIT","readmeFilename":"README.md"}