cli-nano 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,6 +5,7 @@
5
5
  [![npm](https://img.shields.io/npm/v/cli-nano.svg)](https://www.npmjs.com/package/cli-nano)
6
6
  [![npm](https://img.shields.io/npm/dy/cli-nano)](https://www.npmjs.com/package/cli-nano)
7
7
  [![npm bundle size](https://img.shields.io/bundlephobia/minzip/cli-nano?color=success&label=gzip)](https://bundlephobia.com/result?p=cli-nano)
8
+ <a href="https://nodejs.org/en/about/previous-releases"><img src="https://img.shields.io/node/v/cli-nano.svg" alt="Node" /></a>
8
9
 
9
10
  ## cli-nano
10
11
 
@@ -87,10 +88,13 @@ const config: Config = {
87
88
  display: {
88
89
  alias: 'D',
89
90
  required: true,
91
+ type: 'boolean',
90
92
  description: 'a required display option',
91
93
  }
92
94
  },
93
95
  version: '0.1.6',
96
+ helpOptLength: 18, // option name length shown in help (defaults to 20)
97
+ helpDescLength: 60, // description length shown in help (defaults to 65)
94
98
  };
95
99
 
96
100
  const args = parseArgs(config);
@@ -100,6 +104,31 @@ console.log(args);
100
104
  // startServer(args);
101
105
  ```
102
106
 
107
+ ### Usage with Type Inference
108
+
109
+ For full TypeScript auto-inference and IntelliSense of parsed arguments, define your config as a `const` and use `as const`:
110
+
111
+ ```ts
112
+ const config = {
113
+ ... // your config object as shown above
114
+ } as const;
115
+
116
+ const args = parseArgs<typeof config>(config);
117
+
118
+ // TypeScript will infer the correct types:
119
+ args.input; // [string, ...string[]] (required, variadic)
120
+ args.port; // number (optional, has default)
121
+ args.verbose; // boolean (optional)
122
+ args.display; // boolean (required)
123
+ ```
124
+
125
+ > **Tip:**
126
+ > Using `as const` preserves literal types and tuple information, so TypeScript can infer required/optional fields and argument types automatically.
127
+ > If you use `const config: Config = { ... }`, you get type checking but not full IntelliSense for parsed arguments.
128
+
129
+ > [!NOTE]
130
+ > For required+variadic positionals, the type is `[string, ...string[]]` (at least one value required). For optional variadic, it's string[]. For non-variadic, it's string.
131
+
103
132
  #### Example CLI Calls
104
133
 
105
134
  ```sh
@@ -146,4 +175,32 @@ See [examples/](examples/) for more usage patterns.
146
175
  `cli-nano` is currently used in these other projects of mine (feel free to edit this list):
147
176
 
148
177
  - [native-copyfiles](https://github.com/ghiscoding/native-copyfiles)
149
- - [remove-glob](https://github.com/ghiscoding/remove-glob)
178
+ - [remove-glob](https://github.com/ghiscoding/remove-glob)
179
+
180
+ ## Help Example
181
+
182
+ You can see below an example of a CLI help (which is the result of calling `--help` with the config shown avove).
183
+
184
+ Please note:
185
+
186
+ - `<option>` → required
187
+ - `[option]` → optional
188
+
189
+ ```
190
+ Usage:
191
+ serve <input..> [port] [options] Start a server with the given options
192
+
193
+ Arguments:
194
+ input serving files or directory <string..>
195
+ port port to bind on [number]
196
+
197
+ Options:
198
+ -d, --dryRun Show what would be done, but do not actually start the se... [boolean]
199
+ -e, --exclude pattern or glob to exclude (may be passed multiple times) [array]
200
+ -r, --rainbow Enable rainbow mode [boolean]
201
+ -V, --verbose print more information to console [boolean]
202
+ --up slice a path off the bottom of the paths [number]
203
+ -D, --display a required display option <boolean>
204
+ -h, --help Show help [boolean]
205
+ -v, --version Show version number [boolean]
206
+ ```
@@ -0,0 +1 @@
1
+ export { };