{"id":16296413,"url":"https://github.com/evenstensberg/proportional","last_synced_at":"2026-01-20T05:33:06.625Z","repository":{"id":103583648,"uuid":"136833353","full_name":"evenstensberg/proportional","owner":"evenstensberg","description":"A library to make CLI's easier to work with","archived":false,"fork":false,"pushed_at":"2022-11-22T13:24:26.000Z","size":509,"stargazers_count":2,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-13T22:52:17.761Z","etag":null,"topics":["0cjs","cli","command-line-tool"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evenstensberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["evenstensberg"]}},"created_at":"2018-06-10T18:13:09.000Z","updated_at":"2025-01-19T11:28:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"58afc1c1-b392-490f-8dfa-87c67f224ee3","html_url":"https://github.com/evenstensberg/proportional","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evenstensberg%2Fproportional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evenstensberg%2Fproportional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evenstensberg%2Fproportional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evenstensberg%2Fproportional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evenstensberg","download_url":"https://codeload.github.com/evenstensberg/proportional/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247732199,"owners_count":20986814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["0cjs","cli","command-line-tool"],"created_at":"2024-10-10T20:22:27.302Z","updated_at":"2026-01-20T05:33:01.607Z","avatar_url":"https://github.com/evenstensberg.png","language":"JavaScript","funding_links":["https://github.com/sponsors/evenstensberg"],"categories":[],"sub_categories":[],"readme":"# Proportional\n\n`Proportional` is a library for CLI tools intended to make users having a better time. Many new users struggle when starting with advanced tools or tools in general, most likely due the complexity of many tools out there today.\n\nA common approach to this problem is 0CJS. It consists of only requiring the bare minimum for users to use the tool you have created. This tool is an extention of that. By gradually adapting the CLI for users over time or by invoking a command, the developer experience could become better over time. \n\n\n# Usage\n\nThe library exposes a simple interface derived from [`yargs`](https://github.com/yargs/yargs). By using yargs's convention when creating your CLI, you will be able to create a CLI within a simple scope of yargs. Not all methods from yargs methods are supported.\n\n# Installation\n\n### Using npm\n`$ npm install --save proportional`\n### Using yarn\n`$ yarn add proportional`\n\n# Example\n```js\nconst Proportional = require('proportional');\n\nconst CLI = new Proportional();\n\nCLI.levels(['webpagetest', 'lighthouse', 'psi']);\n\nCLI.threshold({\n  webpagetest: 1,\n  lighthouse: 2,\n  psi: 3,\n});\n\nCLI.hook({\n  webpagetest: () =\u003e require('./node_modules/.bin/webpagetest'),\n  lighthouse: () =\u003e require('./node_modules/.bin/lighthouse'),\n  psi: () =\u003e require('./node_modules/.bin/psi'),\n});\n\nCLI.run(process.argv.slice(2));\n```\n\nMore examples are found in the `examples` directory.\n\n# API\n\n### threshold\n\nThreshold is a way to specify how many times the current CLI should be used before it should switch to another higher alternative. By setting the threshold, you could allow users to gradually shift towards a more complex CLI over time.\n\n```js\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.threshold({\n  levelOne: 10,\n  levelTwo: 20,\n  levelThree: 30,\n});\n\n```\n### usage\n\nUsage works as it does with yargs. The usage option is visible when the user types a wrong command and it accepts an object.\n\n```js\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.usage({\n  levelOne: 'Seems like you missed the init option! try again with init!',\n  levelTwo: 'Ipsum Lorem',\n  levelThree: 'This is way to advanced'\n});\n```\n\n### version\n\nPass the version number to be used when outputting the help flag.\n\n```js\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.version({\n  levelOne: '1.2.3',\n  levelTwo: '4.5.6',\n  levelThree: '8.9.10'\n});\n```\n\n```js\nCLI.version('1.34.5');\n```\n\n### levels\n\nBy setting `levels`, you specify which CLI should be run. In order for the tool to know which cli to change to, you need to match this option(array) with `threshold` and/or `hook`.\n\n```js\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.levels(['levelOne', 'levelTwo', 'levelThree']);\n```\n### defaultLevel\n\nYou can specify a default level for your tool to start using.\n```js\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.levels(['levelOne', 'levelTwo', 'levelThree']);\nCLI.defaultLevel('levelOne');\n```\n\n### hook\n\nThis option allows you to tap into other CLI's when creating your tool. The function expects an object with the keys being your levels and the value being the module you are going to use. This tool handles `process.env` for you, so if you combine the tool with arguments that are supported in this libary, it will not be used in the module you are using.\n\n```js\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.hook({\n  levelOne: () =\u003e require('./node_modules/.bin/easy'),\n  levelTwo: () =\u003e require('./node_modules/.bin/medium'),\n  levelThree: () =\u003e require('./node_modules/.bin/hard'),\n});\n```\n\n### alias\n\nAlias works as yargs handles aliases. You can either supply it through options, or with an own flag.\n\n```js\nCLI.alias({\n  k: 'k',\n  p: 'p'\n});\n```\n\n### options\n\nOptions are handled the same way as yargs handles an option, however, this follows the key/value convention where you need to pass the level as the key and the option to be the value.\n\n```js\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.options({\n  levelOne: {\n    alright: {\n      type: 'boolean',\n      alias: 'a',\n      describe: 'AaA?',\n    },\n    bC00l: {\n      type: 'boolean',\n      describe: 'B c00l :)',\n    },\n  },\n  levelTwo: {...}\n})\n```\n\n### upgrade\n\nIf you want to switch to another CLI at runtime you can use the `upgrade` flag, or use the built in function to do it at \"compile-time\".\n\nIf you use the function, you can either supply a string(being the level you want to change to), or call the function without any arguments, where the tool will read your `.proportional` configuration to determine which CLI to swap to.\n\n```js\n\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.upgrade(\"levelOne\");\n```\n\n```js\n\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.upgrade();\n```\n\n`$ node ./my/path.js upgrade --help`\n\n### downgrade\n\n\nDowngrade works similarly as `upgrade`.\n\n```js\n\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.downgrade(\"levelOne\");\n```\n\n```js\n\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\nCLI.downgrade();\n```\n\n`$ node ./my/path.js downgrade --help`\n\n### run\n\nTo run the CLI, you will need to invoke the `run` method. If you built the tool using options, aliases et al. from `proportional`, `output` and `argv` is given back to you. If you use `hooks`, nothing is returned. To handle both cases (hooks and your own CLI), see `examples/webpack`.\n\n```js\n\nconst Proportional = require('proportional');\nconst CLI = new Proportional();\n\n// or const results = CLI.run(process.argv.slice(2))\nCLI.run(process.argv.slice(2));\n```\n\n### misc\n\nYou can also pass the level to the CLI you want to swap to if you want to. If you have set the level `thisLevel` programatically, but your current level is `previousLevel` you can swap to the level by calling `node ./path/to/myCLI.js thisLevel \u003cargs\u003e`.\n\n`$ node ./my/path.js levelTwo --help`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevenstensberg%2Fproportional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevenstensberg%2Fproportional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevenstensberg%2Fproportional/lists"}