@thi.ng/args 2.2.33 → 2.2.35

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-08-27T11:20:58Z
3
+ - **Last updated**: 2023-09-06T13:36:28Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -84,13 +84,28 @@ Package sizes (brotli'd, pre-treeshake): ESM: 2.29 KB
84
84
 
85
85
  ### Basic usage
86
86
 
87
- ```ts
87
+ ```ts tangle:export/readme.ts
88
+ import {
89
+ flag,
90
+ hex,
91
+ json,
92
+ kvPairs,
93
+ oneOf,
94
+ parse,
95
+ size,
96
+ string,
97
+ vec,
98
+ type Args,
99
+ type KVDict,
100
+ type Tuple,
101
+ } from "@thi.ng/args";
102
+
88
103
  type ImgType = "png" | "jpg" | "gif" | "tiff";
89
104
 
90
105
  // CLI args will be validated against this interface
91
106
  interface TestArgs {
92
107
  configPath?: string;
93
- force: boolean;
108
+ force?: boolean;
94
109
  bg: number;
95
110
  type: ImgType;
96
111
  size?: Tuple<number>;
@@ -120,6 +135,7 @@ const specs: Args<TestArgs> = {
120
135
  desc: "Background color",
121
136
  // mandatory args require a `default` value and/or `optional: false`
122
137
  default: 0xffffff,
138
+ defaultHint: "ffffff",
123
139
  }),
124
140
  // enum value (mandatory)
125
141
  type: oneOf(["png", "jpg", "gif", "tiff"], {
@@ -134,24 +150,76 @@ const specs: Args<TestArgs> = {
134
150
  size: size(2, { hint: "WxH", desc: "Target size" }),
135
151
  // another version for tuples of floating point values
136
152
  // pos: tuple(coerceFloat, 2, { desc: "Lat/Lon" }, ","),
137
- pos: vec(2, { desc: "Lat/Lon" }),
153
+ pos: vec(2, { desc: "Lat/Lon coordinates" }),
138
154
  // JSON string arg
139
155
  xtra: json({
140
156
  alias: "x",
141
157
  desc: "Extra options",
158
+ group: "extra",
142
159
  }),
143
160
  // key-value pairs parsed into an object
144
- define: kvPairs({ alias: "D", desc: "Define dict entry" }),
161
+ define: kvPairs({
162
+ alias: "D",
163
+ desc: "Define dict entry",
164
+ group: "extra"
165
+ }),
145
166
  };
146
167
 
147
168
  try {
148
169
  // parse argv w/ above argument specs & default options
149
170
  // (by default usage is shown if error occurs)
150
- const args = parse(specs, process.argv);
171
+ const args = parse(specs, process.argv, {
172
+ usageOpts: {
173
+ prefix: `
174
+ █ █ █ │
175
+ ██ █ │
176
+ █ █ █ █ █ █ █ █ │ @thi.ng/args demo app
177
+ █ █ █ █ █ █ █ █ █ │ v1.0.0
178
+ █ │
179
+ █ █ │\n\n`,
180
+ showGroupNames: true,
181
+ groups: ["flags", "main", "extra"],
182
+ lineWidth: 72,
183
+ },
184
+ });
151
185
  console.log(args);
152
186
  } catch (_) {}
153
187
  ```
154
188
 
189
+ Invoking this as CLI script without arguments will generate an error about a
190
+ missing `--type` arg and output the generated usage info (by default with ANSI
191
+ color highlights):
192
+
193
+ ```text
194
+ illegal argument(s): missing arg: --type
195
+
196
+ █ █ █ │
197
+ ██ █ │
198
+ █ █ █ █ █ █ █ █ │ @thi.ng/args demo app
199
+ █ █ █ █ █ █ █ █ █ │ v1.0.0
200
+ █ │
201
+ █ █ │
202
+
203
+ Flags:
204
+
205
+ -f, --force Force operation
206
+
207
+ Main:
208
+
209
+ --bg HEX Background color (default: "ffffff")
210
+ -c PATH, --config-path PATH Config file path (CLI args always take
211
+ precedence over those settings)
212
+ --pos N,N Lat/Lon coordinates
213
+ --size WxH Target size
214
+ -t ID, --type ID [required] Image type: "png", "jpg",
215
+ "gif", "tiff"
216
+
217
+ Extra:
218
+
219
+ -D key=val, --define key=val [multiple] Define dict entry
220
+ -x JSON, --xtra JSON Extra options
221
+ ```
222
+
155
223
  #### Generate & display help
156
224
 
157
225
  Usage information can be generated via `usage()` and is automatically triggered
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/args",
3
- "version": "2.2.33",
3
+ "version": "2.2.35",
4
4
  "description": "Declarative, functional & typechecked CLI argument/options parser, value coercions etc.",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -37,7 +37,7 @@
37
37
  "@thi.ng/api": "^8.9.5",
38
38
  "@thi.ng/checks": "^3.4.5",
39
39
  "@thi.ng/errors": "^2.3.5",
40
- "@thi.ng/strings": "^3.4.13"
40
+ "@thi.ng/strings": "^3.5.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@microsoft/api-extractor": "^7.36.4",
@@ -96,5 +96,5 @@
96
96
  "thi.ng": {
97
97
  "year": 2018
98
98
  },
99
- "gitHead": "5929dd20497668496af13415cdf784a4d6f69aa3\n"
99
+ "gitHead": "b2ef5a1b8932d067af4ec2fc7da03d59d6868dc7\n"
100
100
  }