├── .editorconfig
├── .gitattributes
├── .github
├── cli-meow-help.png
└── funding.yml
├── .gitignore
├── .npmrc
├── .prettierrc
├── changelog.md
├── code-of-conduct.md
├── index.js
├── license
├── package.json
├── readme.md
├── test.js
└── utils
├── createTable.js
├── getDefaultValue.js
├── pkg-cmd.js
└── pkg-up.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = tab
5 | end_of_line = lf
6 | charset = utf-8
7 | trim_trailing_whitespace = true
8 | insert_final_newline = true
9 |
10 | [*.yml]
11 | indent_style = space
12 | indent_size = 2
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto eol=lf
2 |
--------------------------------------------------------------------------------
/.github/cli-meow-help.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmadawais/cli-meow-help/2e2484448c59c3262839f7934dbf782976ebe9da/.github/cli-meow-help.png
--------------------------------------------------------------------------------
/.github/funding.yml:
--------------------------------------------------------------------------------
1 | custom:
2 | [
3 | 'https://github.com/ahmadawais/sponsor',
4 | 'https://NodeCLI.com',
5 | 'https://VSCode.pro',
6 | ]
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # NPM #
2 | ##########
3 | # Ignore all directories called node_modules in current folder and any subfolders.
4 | node_modules/
5 | /node_modules/
6 |
7 | # Packages #
8 | ############
9 | *.7z
10 | *.dmg
11 | *.gz
12 | *.bz2
13 | *.iso
14 | *.jar
15 | *.rar
16 | *.tar
17 | *.zip
18 | *.tgz
19 | *.map
20 |
21 | # Logs and databases #
22 | ######################
23 | *.log
24 | *.sql
25 | *.env
26 |
27 | # OS generated files #
28 | ######################
29 | **.DS_Store*
30 | ehthumbs.db
31 | Icon?
32 | Thumbs.db
33 | ._*
34 |
35 | # Vim generated files #
36 | ######################
37 | *.un~
38 |
39 | # SASS #
40 | ##########
41 | **/.sass-cache
42 | **/.sass-cache/*
43 | **/.map
44 |
45 | # Composer #
46 | ##########
47 | !assets/js/vendor/
48 | wpcs/
49 | /vendor/
50 |
51 | # Bower #
52 | ##########
53 | assets/bower_components/*
54 |
55 | # Codekit #
56 | ##########
57 | /codekit-config.json
58 | *.codekit
59 | **.codekit-cache/*
60 |
61 | # Compiled Files and Build Dirs #
62 | ##########
63 | /README.html
64 |
65 | # PhpStrom Project Files #
66 | .idea/
67 | library/vendors/composer
68 | assets/img/.DS_Store
69 |
70 | # No lock files.
71 | package-lock.json
72 | yarn.lock
73 |
74 | # Build files.
75 | dist/
76 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | package-lock=false
2 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "trailingComma": "none",
3 | "bracketSpacing": false,
4 | "arrowParens": "avoid",
5 | "singleQuote": true,
6 | "printWidth": 80,
7 | "useTabs": true,
8 | "tabWidth": 4,
9 | "semi": true
10 | }
11 |
--------------------------------------------------------------------------------
/changelog.md:
--------------------------------------------------------------------------------
1 | # CHANGELOG
2 |
3 | [](https://twitter.com/MrAhmadAwais/) [](https://www.linkedin.com/in/MrAhmadAwais/) [](https://youtube.com/AhmadAwais?sub_confirmation=1) [](https://AhmadAwais.com/) [](https://github.com/ahmadawais)
4 |
5 | > I have released a video course to help you build Node.js CLIs for Automation →
6 |
7 | > [Support my work][sponsor]: Hey there! If you or your company have been benefiting from any of my projects or simply appreciate the awesomeness I bring to the table, why not consider backing me up? I'm committed to sticking around for the long haul, tirelessly advocating for open-source development.
8 |
9 | [][s]
10 |
11 | ❯❯ Professional Development Courses ↓
12 |
13 | [][n] [][v] [-gray.svg?colorA=21262D&colorB=30363D&style=for-the-badge)][nj]
14 |
15 | [s]: https://github.com/AhmadAwais/sponsor
16 | [n]: https://NodeCLI.com?utm_source=github.com/ahmadawais/changelog&utm_medium=referral&utm_campaign=changelog
17 | [v]: https://VSCode.pro?utm_source=github.com/ahmadawais/changelog&utm_medium=referral&utm_campaign=changelog
18 | [nj]: https://NodejsBeginner.com?utm_source=github.com/ahmadawais/changelog&utm_medium=referral&utm_campaign=changelog
19 | [g]: https://github.com/AhmadAwais
20 | [sponsor]: https://github.com/AhmadAwais/sponsor
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | [](changelog.md)
30 |
31 | All notable changes in this project's [released versions](../../releases) are documented in this file.
32 |
33 | > **CHANGELOG KEY**: `📦 NEW`, `👌 IMPROVE`, `🐛 FIX`, `📖 DOC`, `🚀 RELEASE`, `🤖 TEST`, and `‼️ BREAKING`.
34 |
35 |
36 |
37 | > _I use [Emoji-log](https://github.com/ahmadawais/Emoji-Log), you should try it and simplify your git commits._
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | ### RELEASE: [4.0.0](https://github.com/ahmadawais/cli-meow-help/compare/3.2.0...4.0.0)
49 |
50 |
51 | 
52 |
53 | > ‼️ Require no longer supported moving to ESM based syntax
54 |
55 | 
56 |
57 | > 👌 Latest chalk and chalkTemplate [`41e2587`](https://github.com/ahmadawais/cli-meow-help/commit/41e25875417cfd74abe7ef21129884cafb1fb930)
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | ### RELEASE: [3.2.0](https://github.com/ahmadawais/cli-meow-help/compare/3.1.0...3.2.0)
67 |
68 | 
69 |
70 | > 📦 shortFlag support [`5bbf37e`](https://github.com/ahmadawais/cli-meow-help/commit/5bbf37e2863b1c549845b165aed17ebc3b7e3ffc)
71 |
72 | 
73 |
74 | > 📖 Changelog [`ee4b112`](https://github.com/ahmadawais/cli-meow-help/commit/ee4b112928add40af1821ee78c9e058a89d8aff1)
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | ### RELEASE: [3.1.0](https://github.com/ahmadawais/cli-meow-help/compare/3.0.0...3.1.0)
84 |
85 | 
86 |
87 | > 👌 Lingo Example or Examples for more examples [`89516a2`](https://github.com/ahmadawais/cli-meow-help/commit/89516a275b64e3ba4ad572ec5babff3fe665faad)
88 |
89 | 
90 |
91 | > 📖 Changelog [`fe82b1b`](https://github.com/ahmadawais/cli-meow-help/commit/fe82b1b92a97409375b89cbd686a1d15c5ff5062)
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 | ### RELEASE: [3.0.0](https://github.com/ahmadawais/cli-meow-help/compare/2.0.2...3.0.0)
101 |
102 | 
103 |
104 | > 📦 Examples [`b6c12ee`](https://github.com/ahmadawais/cli-meow-help/commit/b6c12ee444928cb3819c2e236d53e9c18bf76a21)
105 |
106 | 
107 |
108 | > 📖 Changelog [`9fd84e8`](https://github.com/ahmadawais/cli-meow-help/commit/9fd84e83c74cd125f6170ada4b239bdf32777928)
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 | ### RELEASE: [2.0.2](https://github.com/ahmadawais/cli-meow-help/compare/2.0.1...2.0.2)
118 |
119 | 
120 |
121 | > 📖 Changelog [`9256c96`](https://github.com/ahmadawais/cli-meow-help/commit/9256c96384968d6f847904b74c198aa4059d56ad)
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 | ### RELEASE: [2.0.1](https://github.com/ahmadawais/cli-meow-help/compare/2.0.0...2.0.1)
131 |
132 | 
133 |
134 | > 👌 Lingo [`177c812`](https://github.com/ahmadawais/cli-meow-help/commit/177c8129f973d3b56e29d2a4db08a6c69a54c274)
135 |
136 | 
137 |
138 | > 📖 Changelog [`1ccda80`](https://github.com/ahmadawais/cli-meow-help/commit/1ccda80da914127c0babf96f46b590caadb24412)
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 | ### RELEASE: [2.0.0](https://github.com/ahmadawais/cli-meow-help/compare/1.0.4...2.0.0)
148 |
149 | 
150 |
151 | > 🐛 Deps [`7afbb69`](https://github.com/ahmadawais/cli-meow-help/commit/7afbb69f036cb9d85230998583e9c7e4b6709c27)
152 |
153 | 
154 |
155 | > 📖 Changelog [`48ea888`](https://github.com/ahmadawais/cli-meow-help/commit/48ea888f3d2d323459ac52c8059b6aec0f9518d6)
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 | ### RELEASE: [1.0.4](https://github.com/ahmadawais/cli-meow-help/compare/1.0.3...1.0.4)
165 |
166 | 
167 |
168 | > 📖 Changelog [`541508d`](https://github.com/ahmadawais/cli-meow-help/commit/541508dd899c15b393bb7394a1f0f35d80a68244)
169 |
170 | > 📖 Ref to meow [`7327cf4`](https://github.com/ahmadawais/cli-meow-help/commit/7327cf4572432639f4ffd7f2efc390a6e9158cdf)
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 | ### RELEASE: [1.0.3](https://github.com/ahmadawais/cli-meow-help/compare/1.0.2...1.0.3)
180 |
181 | 
182 |
183 | > 🐛 Link [`cc093c7`](https://github.com/ahmadawais/cli-meow-help/commit/cc093c742e7722382ceb09fe2fa77109ef80e23a)
184 |
185 | 
186 |
187 | > 📖 Changelog [`135f123`](https://github.com/ahmadawais/cli-meow-help/commit/135f12394a6af750a031386223da40809fc1691d)
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 | ### RELEASE: [1.0.2](https://github.com/ahmadawais/cli-meow-help/compare/1.0.1...1.0.2)
197 |
198 | 
199 |
200 | > 🐛 Link [`dae39db`](https://github.com/ahmadawais/cli-meow-help/commit/dae39db23cc219d47d14b01788954d7387846593)
201 |
202 | 
203 |
204 | > 📖 Changelog [`3ea05ee`](https://github.com/ahmadawais/cli-meow-help/commit/3ea05eea525f6a185162f131e9ddb7cbc2ed447b)
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 | ### RELEASE: [1.0.1](https://github.com/ahmadawais/cli-meow-help/compare/1.0.0...1.0.1)
214 |
215 | 
216 |
217 | > 📦 Sponsor [`900c90f`](https://github.com/ahmadawais/cli-meow-help/commit/900c90f6665b1ee70b5eb9eb2b896d2982e95ff6)
218 |
219 | 
220 |
221 | > 📖 Changelog [`83f27d7`](https://github.com/ahmadawais/cli-meow-help/commit/83f27d74ece70d5283083145c3432637edec200d)
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 | ### RELEASE: 1.0.0
231 |
232 | 
233 |
234 | > 📦 First commit [`33bc4dc`](https://github.com/ahmadawais/cli-meow-help/commit/33bc4dc68500d7032156daea7feabbc1efa0beb9)
235 |
236 | > 📦 First version [`ece26b7`](https://github.com/ahmadawais/cli-meow-help/commit/ece26b7d6043d1fa3992bc9cae19f17edef3345e)
237 |
238 | > 📦 Spacing Docs [`292bb27`](https://github.com/ahmadawais/cli-meow-help/commit/292bb27bb15b277f010728c08bd21e24ab0d0322)
239 |
240 | 
241 |
242 | > 👌 Format [`3de92ac`](https://github.com/ahmadawais/cli-meow-help/commit/3de92acfc7bcc82c6595ca7eea3b21b84f9712e0)
243 |
244 | 
245 |
246 | > 📖 Changelog [`6d7fe94`](https://github.com/ahmadawais/cli-meow-help/commit/6d7fe94d8722f383deb587c80049bdd362009e59)
247 |
248 | > 📖 API [`56f95ef`](https://github.com/ahmadawais/cli-meow-help/commit/56f95ef6237ae2fd869597dfb6fb361cb21c1203)
249 |
250 | > 📖 Credit [`ca69f71`](https://github.com/ahmadawais/cli-meow-help/commit/ca69f71077348542dc4d0d0c7b99c292cb387eff)
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 | [s]: https://github.com/AhmadAwais/sponsor
260 | [n]: https://NodeCLI.com?utm_source=github.com/ahmadawais/changelog&utm_medium=referral&utm_campaign=changelog
261 | [v]: https://VSCode.pro?utm_source=github.com/ahmadawais/changelog&utm_medium=referral&utm_campaign=changelog
262 | [nj]: https://NodejsBeginner.com?utm_source=github.com/ahmadawais/changelog&utm_medium=referral&utm_campaign=changelog
263 | [g]: https://github.com/AhmadAwais
264 | [sponsor]: https://github.com/AhmadAwais/sponsor
265 |
--------------------------------------------------------------------------------
/code-of-conduct.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, gender identity and expression, level of experience,
9 | nationality, personal appearance, race, religion, or sexual identity and
10 | orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at me@AhmadAwais.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at [https://contributor-covenant.org/version/1/4][version]
72 |
73 | [homepage]: https://contributor-covenant.org
74 | [version]: https://contributor-covenant.org/version/1/4/
75 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Cli `meow` Helper.
3 | *
4 | * Generate automatically formatted help text for `meow` CLI helper
5 | *
6 | * @autor Awais
7 | */
8 |
9 | import chalk from 'chalk';
10 | import chalkTemplate from 'chalk-template';
11 |
12 | import createTable from './utils/createTable.js';
13 | import getDefaultValue from './utils/getDefaultValue.js';
14 |
15 | const dim = chalk.dim;
16 | const greenInverse = chalk.bold.inverse.green;
17 | const cyanInverse = chalk.bold.inverse.cyan;
18 | const yellowInverse = chalk.bold.inverse.yellow;
19 |
20 | export default ({
21 | name = `(CLI name undefined)`,
22 | desc,
23 | commands = {},
24 | flags = {},
25 | examples = [],
26 | defaults = true,
27 | header,
28 | footer
29 | }) => {
30 | let help = '';
31 | const spacer = `\n\n`;
32 |
33 | if (header) {
34 | help += `${header}${spacer}`;
35 | }
36 |
37 | if (desc) {
38 | help += `${desc}${spacer}`;
39 | }
40 |
41 | // Usage.
42 | help += `${greenInverse(` USAGE `)} ${spacer}`;
43 | help += chalkTemplate`{gray $} {green ${name}} {cyan } {yellow [option]}`;
44 | let isPlural;
45 |
46 | if (examples.length) {
47 | isPlural = examples.length > 1 ? `S` : ``;
48 | help += `${spacer}${chalkTemplate`{gray EXAMPLE${isPlural} }`}`;
49 | examples.map(ex => {
50 | const exFlags = ex.flags ? `--${ex.flags.join(` --`)}` : ``;
51 | help += chalkTemplate`\n{gray $} {green ${name}} {cyan ${ex.command}} {yellow ${exFlags}}`;
52 | });
53 | }
54 |
55 | // Commands.
56 | help += `${spacer}${cyanInverse(` COMMANDS `)} ${spacer}`;
57 | const tableCommands = createTable();
58 | const commandKeys = Object.keys(commands);
59 |
60 | for (const command of commandKeys) {
61 | let options = commands[command];
62 | const defaultValue = getDefaultValue(defaults, options);
63 |
64 | tableCommands.push([
65 | chalkTemplate`{cyan ${command}}`,
66 | `${options.desc} ${dim(defaultValue)}`
67 | ]);
68 | }
69 | help += tableCommands.toString();
70 |
71 | // Flags.
72 | help += `${spacer}${yellowInverse(` OPTIONS `)} ${spacer}`;
73 | const tableFlags = createTable();
74 | const flagKeys = Object.keys(flags);
75 |
76 | for (const flag of flagKeys) {
77 | let options = flags[flag];
78 | let alias = options.alias ? `-${options.alias}, ` : ``;
79 | let shortFlag = options.shortFlag ? `-${options.shortFlag}, ` : ``;
80 | const defaultValue = getDefaultValue(defaults, options);
81 |
82 | tableFlags.push([
83 | chalkTemplate`{yellow ${alias}${shortFlag}--${flag}}`,
84 | `${options.desc} ${dim(defaultValue)}`
85 | ]);
86 | }
87 |
88 | help += tableFlags.toString();
89 | help += `\n`;
90 |
91 | if (footer) {
92 | help += `\n${footer}\n`;
93 | }
94 |
95 | return help;
96 | };
97 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2020-present Ahmad Awais.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a
6 | copy of this software and associated documentation files (the "Software"),
7 | to deal in the Software without restriction, including without limitation
8 | the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 | and/or sell copies of the Software, and to permit persons to whom the
10 | Software is furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 | DEALINGS IN THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cli-meow-help",
3 | "version": "4.0.0",
4 | "description": "Generate automatically formatted help text for `meow` CLI helper",
5 | "license": "MIT",
6 | "repository": "ahmadawais/cli-meow-help",
7 | "author": {
8 | "name": "Ahmad Awais",
9 | "email": "me@AhmadAwais.com",
10 | "url": "https://twitter.com/MrAhmadAwais"
11 | },
12 | "main": "dist/index.cjs",
13 | "files": [
14 | "dist",
15 | "*.d.ts"
16 | ],
17 | "keywords": [
18 | "cli-meow-help",
19 | "Ahmad Awais",
20 | "ahmadawais"
21 | ],
22 | "devDependencies": {
23 | "@types/node": "^22.2.0",
24 | "prettier": "^3.3.3",
25 | "tsup": "^8.2.4",
26 | "typescript": "^5.5.4"
27 | },
28 | "scripts": {
29 | "test": "node test.js",
30 | "format": "prettier --write \"./**/*.{js,json}\"",
31 | "dev": "npm run build -- --watch",
32 | "build": "tsup index.js --format cjs,esm --dts --sourcemap --clean --minify --shims",
33 | "prepublishOnly": "npm run build"
34 | },
35 | "dependencies": {
36 | "chalk": "^5.3.0",
37 | "chalk-template": "^1.1.0",
38 | "cli-table3": "^0.6.0"
39 | },
40 | "type": "module",
41 | "module": "dist/index.js",
42 | "types": "dist/index.d.ts",
43 | "exports": {
44 | ".": {
45 | "import": {
46 | "types": "./dist/index.d.ts",
47 | "default": "./dist/index.js"
48 | },
49 | "require": {
50 | "types": "./dist/index.d.cts",
51 | "default": "./dist/index.cjs"
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | [](./../../)
2 |
3 | # cli-meow-help
4 |
5 | [](https://www.npmjs.com/package/cli-meow-help) [](https://NodeCLI.com/?utm_source=FOSS) [](https://VSCode.pro/?utm_source=FOSS) [](https://github.com/ahmadawais/sponsor?utm_source=FOSS)
6 | [](https://twitter.com/mrahmadawais/)
7 |
8 | > Generate automatically formatted help text for [`meow`](https://github.com/sindresorhus/meow) CLI helper
9 |
10 |
11 |
12 | [](./../../)
13 |
14 | ## Install
15 |
16 | ```sh
17 | npm install meow cli-meow-help
18 | ```
19 |
20 |
21 |
22 | [](./../../)
23 |
24 | ## Usage
25 |
26 | ```js
27 | const meow = require('meow');
28 | const meowHelp = require('cli-meow-help');
29 |
30 | const commands = {
31 | new: {desc: `Creates a new user account`},
32 | duplicate: {desc: `Duplicates a user account`}
33 | };
34 |
35 | const flags = {
36 | random: {
37 | desc: `Prints random data`,
38 | type: 'boolean',
39 | default: true
40 | }
41 | };
42 |
43 | const helpText = meowHelp({
44 | name: `cli-command`,
45 | flags,
46 | commands
47 | });
48 |
49 | meow(helpText, {flags});
50 |
51 | // Now run `cli-command --help` to view the
52 | // following auto formatted & generated help info.
53 | ```
54 |
55 | [](./../../)
56 |
57 |
58 |
59 | [](./../../)
60 |
61 | ## API
62 |
63 | ### meowHelp(options)
64 |
65 | #### ❯ options
66 |
67 | Type: `object`
68 |
69 | Default: ↓
70 |
71 | ```js
72 | {
73 | name = `(CLI name undefined)`,
74 | desc,
75 | commands = {},
76 | flags = {},
77 | examples = [],
78 | defaults = true,
79 | header,
80 | footer
81 | }
82 | ```
83 |
84 | You can specify the options below.
85 |
86 | #### ❯ name
87 |
88 | Type: `string`
89 | Default: `(CLI name undefined)`
90 |
91 | The `bin` command name of the cli that's used to run the CLI. Examples: `corona` for the [corona-cli](https://github.com/AhmadAwais/corona-cli) that's installed globally or `npx corona-cli` for if `npx` is the recommended usage.
92 |
93 | #### ❯ desc
94 |
95 | Type: `string`
96 | Default: `undefined` (optional)
97 |
98 | Optionally define a description text for the help message.
99 |
100 | #### ❯ commands
101 |
102 | Type: `string`
103 | Default: `{}` (optional)
104 |
105 | Optionally, define a JavaScript object containing info on the CLI commands (i.e. `meow` inputs). Each command has a `desc` property to define the help text.
106 |
107 | #### ❯ flags
108 |
109 | Type: `string`
110 | Default: `{}`
111 |
112 | Define CLI options (i.e. `meow` flags) just like you do with `meow` which is the `flags` JavaScript object containing each flag with an extra `desc` property to define the help text.
113 |
114 | ##### > examples
115 |
116 | Type: `Array`
117 | Default: `[]`
118 |
119 | List optional examples of how to use the CLI.
120 |
121 | > Check the [test](./test.js) file for more context. Format example:
122 |
123 | ```js
124 | const examples = [
125 |
126 | {
127 | command: `new`,
128 | flags: [`random`]
129 | }
130 | ];
131 | ```
132 |
133 |
134 | #### ❯ defaults
135 |
136 | Type: `string`
137 | Default: `true` (optional)
138 |
139 | Prints out the default values of flags. Set to `false` to disable.
140 |
141 | #### ❯ header
142 |
143 | Type: `string`
144 | Default: `undefined` (optional)
145 |
146 | Optionally, add additional header information.
147 |
148 | #### ❯ footer
149 |
150 | Type: `string`
151 | Default: `undefined` (optional)
152 |
153 | Optionally, add additional footer information.
154 |
155 |
156 |
157 | [](changelog.md)
158 |
159 | ## Changelog
160 |
161 | [❯ Read the changelog here →](changelog.md)
162 |
163 |
164 |
165 | **KEY**: `📦 NEW`, `👌 IMPROVE`, `🐛 FIX`, `📖 DOC`, `🚀 RELEASE`, and `🤖 TEST`
166 |
167 | > _I use [Emoji-log](https://github.com/ahmadawais/Emoji-Log), you should try it and simplify your git commits._
168 |
169 |
170 |
171 |
172 |
173 | [](./../../)
174 |
175 | ## License & Conduct
176 |
177 | - MIT © [Ahmad Awais](https://twitter.com/MrAhmadAwais/)
178 | - Thanks to Maarten Brakkee for initial implementation
179 | - [Code of Conduct](code-of-conduct.md)
180 |
181 |
182 |
183 | [](./../../)
184 |
185 | ## Connect
186 |
187 |
188 |
(follow) To stay up to date on free & open-source software
189 |
(follow) To get #OneDevMinute daily hot tips & trolls
190 |
(subscribe) To tech talks & #OneDevMinute videos
191 |
(read) In-depth & long form technical articles
192 |
(connect) On the LinkedIn profile y'all
193 |
194 |
195 |
196 |
197 | [](https://github.com/AhmadAwais/sponsor)
198 |
199 | ## Sponsor
200 |
201 | Me ([Ahmad Awais](https://twitter.com/mrahmadawais/)) and my incredible wife ([Maedah Batool](https://twitter.com/MaedahBatool/)) are two engineers who fell in love with open source and then with each other. You can read more [about me here](https://ahmadawais.com/about). If you or your company use any of my projects or like what I’m doing then consider backing me. I'm in this for the long run. An open-source developer advocate.
202 |
203 | [](https://twitter.com/mrahmadawais/)
204 |
205 | ### [NodeCLI.com][n] — Learn to build Node.js CLI Automation
206 |
207 | > This repository is part of the [NodeCLI.com][n] course.
208 |
209 | After building hundreds of developer automation tools used by millions of developers, I am sharing exactly how you can do it yourself with minimum effective effort. Learn to build Node.js & JavaScript based CLI (Command Line Interface) apps. Automate the grunt work, do more in less time, impress your manager, and help the community.
210 | → I'm sharing it all in this online video course. [Node CLI Automation
211 | without wasting a 1,000 hours][n] →
212 |
213 | [][n]
214 |
215 | [][n]
216 |
217 | [n]: https://NodeCLI.com?utm_source=github&utm_medium=referral&utm_campaign=ahmadawais/cli-meow-help
218 |
219 | [](https://github.com/AhmadAwais/sponsor)
220 |
--------------------------------------------------------------------------------
/test.js:
--------------------------------------------------------------------------------
1 | import meowHelp from './index.js';
2 |
3 | const commands = {
4 | new: {desc: `Create a new user account`},
5 | duplicate: {desc: `Duplicates a user account`}
6 | };
7 |
8 | const flags = {
9 | random: {
10 | desc: `Prints some random data`,
11 | type: 'boolean',
12 | alias: `r`, // Old versions of meow used `shortFlag` instead of `alias`.
13 | default: true
14 | },
15 | more: {
16 | desc: `Prints more random data`,
17 | type: 'boolean',
18 | shortFlag: `m`, // Latest addition of meow.
19 | default: true
20 | }
21 | };
22 |
23 | const examples = [
24 | {
25 | command: `new`
26 | },
27 | {
28 | command: `new`,
29 | flags: [`random`]
30 | },
31 | {
32 | command: `new`,
33 | flags: [`random`, `more`]
34 | }
35 | ];
36 |
37 | const helpText = meowHelp({
38 | name: `cli-command`,
39 | flags,
40 | commands,
41 | examples
42 | });
43 |
44 | console.log(helpText);
45 |
--------------------------------------------------------------------------------
/utils/createTable.js:
--------------------------------------------------------------------------------
1 | import Table from "cli-table3";
2 |
3 | export default () => {
4 | return new Table({
5 | chars: {
6 | top: '',
7 | 'top-mid': '',
8 | 'top-left': '',
9 | 'top-right': '',
10 | bottom: '',
11 | 'bottom-mid': '',
12 | 'bottom-left': '',
13 | 'bottom-right': '',
14 | left: '',
15 | 'left-mid': '',
16 | mid: '',
17 | 'mid-mid': '',
18 | right: '',
19 | 'right-mid': '',
20 | middle: ''
21 | },
22 | style: {
23 | 'padding-left': 0,
24 | 'padding-right': 2
25 | },
26 | wordWrap: true
27 | });
28 | };
29 |
--------------------------------------------------------------------------------
/utils/getDefaultValue.js:
--------------------------------------------------------------------------------
1 | import chalk from "chalk";
2 |
3 | let defaultValue = ``;
4 | const defaultText = `Default:`;
5 |
6 | export default (defaults, options) => {
7 | if (defaults && options.default) {
8 | defaultValue = `${defaultText} ${chalk.yellow(`${options.default}`)}`;
9 | } else if (defaults && options.type === `boolean`) {
10 | defaultValue = `${defaultText} ${chalk.yellow(`false`)}`;
11 | }
12 | return defaultValue;
13 | };
14 |
--------------------------------------------------------------------------------
/utils/pkg-cmd.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import returnPackageUp from './pkg-up.js';
4 |
5 | function returnPackageCommand(pkg = returnPackageUp()) {
6 | if (typeof pkg.bin !== 'undefined') {
7 | return Object.keys(pkg.bin)[0];
8 | } else {
9 | return 'meow-help';
10 | }
11 | }
12 |
13 | export default returnPackageCommand;
14 |
--------------------------------------------------------------------------------
/utils/pkg-up.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import path from "path";
4 | import readPkgUp from "read-pkg-up";
5 |
6 | function returnPackageUp(parentModule = module.parent) {
7 | // Prevent caching of this module so module.parent is always accurate
8 | delete require.cache[__filename];
9 |
10 | if (parentModule !== null) {
11 | return readPkgUp.sync({
12 | cwd: path.dirname(parentModule.filename)
13 | }).package;
14 | } else {
15 | return {};
16 | }
17 | }
18 |
19 | export default returnPackageUp;
20 |
--------------------------------------------------------------------------------