{"id":13902891,"url":"https://github.com/saehun/cmdconfig","last_synced_at":"2025-04-06T11:32:33.527Z","repository":{"id":40769519,"uuid":"261604296","full_name":"saehun/cmdconfig","owner":"saehun","description":"Simple configuration CLI generator for nodejs","archived":false,"fork":false,"pushed_at":"2023-01-06T05:05:46.000Z","size":1784,"stargazers_count":11,"open_issues_count":16,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T21:29:13.661Z","etag":null,"topics":["cli","command-line","config","configuration-management","javascript","nodejs","prompt","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/saehun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-05T23:20:39.000Z","updated_at":"2024-07-22T17:05:35.000Z","dependencies_parsed_at":"2023-02-05T09:31:07.995Z","dependency_job_id":null,"html_url":"https://github.com/saehun/cmdconfig","commit_stats":null,"previous_names":["saehun/cmdconfig","minidonut/cmdconfig"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saehun%2Fcmdconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saehun%2Fcmdconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saehun%2Fcmdconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saehun%2Fcmdconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saehun","download_url":"https://codeload.github.com/saehun/cmdconfig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478152,"owners_count":20945257,"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":["cli","command-line","config","configuration-management","javascript","nodejs","prompt","typescript"],"created_at":"2024-08-06T22:01:29.037Z","updated_at":"2025-04-06T11:32:33.233Z","avatar_url":"https://github.com/saehun.png","language":"TypeScript","funding_links":[],"categories":["cli"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eCommand line configuration\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://npmjs.org/package/cmdconfig\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/cmdconfig.svg\" alt=\"version\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://npmjs.org/package/cmdconfig\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/cmdconfig.svg\" alt=\"downloads\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cb\u003eSimple configuration CLI generator\u003c/b\u003e\u003c/br\u003e\n  \u003csub\u003eDeclare schema, provide both argument and interactive configuration CRUD.\u003c/sub\u003e\n\u003c/p\u003e\n\n\u003cbr /\u003e\n\n- **Simple**: Only have 2 API. declare schema and initialize with few options.\n- **Versatile**: Provides both prompt and inline configurations.\n- **Extensible**: Supports environment variable, command line profile overriding.\n- **reliable**: Typecheck for each properties.\n\n## Install\n\n``` shell\n$ npm install --save cmdconfig\n```\n\n## Usage\nLet's assume that we are building an office CLI tool which interact with S3. We need to save the user's configuration in local file, implementing functionality similar to `git config` `aws config`.\n\n![config-prompt](https://github.com/minidonut/cmdconfig/raw/master/docs/config-prompt.png)\n\n``` javascript\n// myapp.js\nconst cmdconfig = require(\"cmdconfig\");\n\nconst configSchema = cmdconfig.schema({\n  \"username\": { type: \"string\", description: \"Name of the user\" },\n  \"bucketRegion\": { type: [\"us-east-1\", \"ap-northeast-2\", \"eu-west-1\"], description: \"Primary region of the bucket\" },\n  \"timeout\": { type: \"number\", description: \"Request timeout in seconds\", shared: true },\n  \"localCache\": { type: \"boolean\", description: \"Save files to a local directory\", shared: true },\n});\n\nconst config = cmdconfig.init({\n  filename: \".myappconfig\",\n  schema: configSchema,\n});\n\nconsole.log(config);\n```\n\n![config-result](https://github.com/minidonut/cmdconfig/raw/master/docs/config-result.png)\n\n## Features\nAfter implemented, `config` command is reserved. commands with options `config --help` and `config --list` are auto generated. If the program starts with `config` command, it's execution will be stopped after configuration procedure is done.\n\n### Inline configuration\n``` shell\n$ myapp config --cache=false --bucketRegion=eu-west-1\n```\n\n### Profile management\nSave and load configs by profile with `profile=PROFILE_NAME` option.\n\n``` shell\n$ myapp config --profile=dev\n✔ username … katarina/dev\n✔ region › ap-northeast-2\n✔ save as 'dev' profile? … yes\n$ myapp --profile=dev\n{\n  username: 'katarina/dev',\n  bucketRegion: 'ap-northeast-2',\n  timeout: 30,\n  localCache: true\n}\n```\n\n### Environment variable\n\n``` javascript\n// myapp.js\n...\nconst config = cmdconfig.init({\n  filename: \".myappconfig\",\n  schema: configSchema,\n  profile: process.env.MY_APP_PROFILE,\n});\n...\n```\n\n``` shell\n$ MY_APP_PROFILE=dev myapp\n{\n  username: 'katarina/dev',\n  bucketRegion: 'ap-northeast-2',\n  timeout: 30,\n  localCache: true\n}\n```\n\n### Overriding\n\n``` shell\n$ myapp --username=katarina/test --localCache=false\n{\n  username: 'katarina/test',\n  bucketRegion: 'us-east-1',\n  timeout: 30,\n  localCache: false\n}\n```\n\n\n### Change base directory and filename\nChange location where the configuration file is saved.\nSave file to `~/.dotfiles/.myappconf` (default `~/.config`):\n\n``` javascript\n// myapp.js\nconst os = require(\"os\");\nconst path = require(\"path\");\n...\nconst config = cmdconfig.init({\n  filename: \".myappconf\",\n  schema: configSchema,\n  base: path.join(os.homedir(), \".dotfiles\"),\n});\n...\n```\n\n\n### Help\n``` shell\n$ myapp config --help\nOptions:\n  --help             Show help                                         [boolean]\n  --list             Show list                                         [boolean]\n  --username         Name of the user                                   [string]\n  --bucketRegion     Primary region of the bucket                       [string]\n  --timeout          Request timeout in seconds                         [number]\n  --localCache       Save files to a local directory                   [boolean]\n```\n\n\n### List\nPrint all configuration details in yaml format.\n``` shell\n$ myapp config --list\n/Users/$USER/.config/.myappconfig\ndefault:\n  username: katarina\n  bucketRegion: us-east-1\ndev:\n  username: katarina/dev\n  bucketRegion: ap-northeast-2\nshared:\n  timeout: 30\n  localCache: false\n```\n\n## API\n### cmdconfig.schema(Schema s)\nreturn: `Schema`\n\nValidate given schema object.\n\n### cmdconfig.init(Option o)\nreturn: `config object`\u003cbr\u003e\n**config object**: plain javascript object with key, value map.\n\nParse commandline argument. if `config` command exist, it saves the configuration and exit. Else, it loads the configuration and provides.\n\n\n## Type\n### `Schema`\n| Key | Type | Description |\n| ----- | :--: | ----------- |\n| key1 | `SchemaItem` | Schema Item for key#1  |\n| key2 | `SchemaItem` | Schema Item for key#2  |\n| key3 | `SchemaItem` | Schema Item for key#3  |\n| ... | ... | ... |\n| keyN | `SchemaItem` | Schema Item for keyN  |\n\n### `SchemaItem`\n| Key | Type | Description |\n| ----- | :--: | ----------- |\n| type | `\"string\"`, `\"number\"`, `\"boolean\"`, `string[]` | type of config's property. Note) \"number\" is string literal. not a number type. |\n| description | `string` | (Optional) property description. It appears in `--help` command  |\n| shared | `boolean` | (Optional) whether the property belongs to profile or shared |\n\n### `Option`\n| Key | Type | Description |\n| ----- | :--: | ----------- |\n| filename | `string` | configuration file name. ex) `\".myappconfig\"`  |\n| schema | `Schema` | Validated schema object. returned from cmdconfig.schema API |\n| profile | `string` | (Optional) pass value from environment variable. ex) `process.env.MY_APP_CONFIG` |\n| base | `string` | (Optional) where config file stored. default `path.join(os.homedir(), \".config\")` (~/.config) |\n\n\n## Typescript\nThis package is written in typescript, generating output type from schema is not supported yet (work in progress).\n\n### Example\n``` typescript\n// src/config.ts\nimport * as cmdconfig from \"cmdconfig\";\n\nconst configSchema = cmdconfig.schema({\n  \"username\": { type: \"string\", description: \"Name of the user\" },\n  \"bucketRegion\": { type: [\"us-east-1\", \"ap-northeast-2\", \"eu-west-1\"], description: \"Primary region of the bucket\" },\n  \"timeout\": { type: \"number\", description: \"Request timeout in seconds\" shared: true },\n  \"localCache\": { type: \"boolean\", description: \"Save files to a local directory\" shared: true },\n});\n\nexport default cmdconfig.init({\n  filename: \".myappconfig\",\n  schema: configSchema,\n}) as {\n  username: string;\n  bucketRegion: \"us-east-1\" | \"ap-northeast-2\" | \"eu-west-1\";\n  timeout: number;\n  localCache: boolean;\n};\n\n\n// src/index.ts\nimport config from \"./config\";\n\nconsole.log(config);\n...\n```\n\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaehun%2Fcmdconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaehun%2Fcmdconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaehun%2Fcmdconfig/lists"}