@optique/env 1.4.0-dev.2633 → 1.4.0-dev.2636

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/dist/index.cjs CHANGED
@@ -21,6 +21,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
 
23
23
  //#endregion
24
+ const __optique_core_doc = __toESM(require("@optique/core/doc"));
25
+ const __optique_core_usage = __toESM(require("@optique/core/usage"));
24
26
  const node_fs = __toESM(require("node:fs"));
25
27
  const node_path = __toESM(require("node:path"));
26
28
  const __optique_core_annotations = __toESM(require("@optique/core/annotations"));
@@ -329,7 +331,8 @@ function createEnvContext(options = {}) {
329
331
  * Since 1.4.0, visible documentation entries include the full environment
330
332
  * variable name in `DocEntry.envVars`. Set `showEnvironment` on the runner
331
333
  * or formatter to display these names without reading their values. Parsers
332
- * without documentation entries, such as `fail()`, have no automatic entry.
334
+ * with `sourceOnly` documentation, such as `fail()`, receive independent
335
+ * environment records. Use `documentation.description` for purpose text.
333
336
  *
334
337
  * @param parser Parser that reads CLI values.
335
338
  * @param options Environment binding options.
@@ -448,12 +451,20 @@ function bindEnv(parser, options) {
448
451
  const defaultValue = upperDefaultValue ?? options.default;
449
452
  const docs = parser.getDocFragments(state, defaultValue);
450
453
  const name = `${options.context.prefix}${options.key}`;
454
+ const hidden = (0, __optique_core_usage.isDocHidden)(options.documentation?.hidden);
455
+ const visibleEntry = docs.fragments.some((fragment) => (fragment.type === "entry" ? [fragment] : fragment.entries).some((entry) => !(0, __optique_core_doc.isDocEntryHidden)(entry) && (0, __optique_core_usage.formatUsageTerm)(entry.term, { context: "doc" }).trim() !== ""));
456
+ const ownBindings = docs.sourceOnly === true || (options.documentation?.description?.length ?? 0) > 0 && visibleEntry ? [{
457
+ name,
458
+ ...options.documentation
459
+ }] : [];
460
+ const bindings = [...ownBindings, ...docs.environmentBindings ?? []];
451
461
  const attach = (entry) => ({
452
462
  ...entry,
453
- envVars: [...new Set([name, ...entry.envVars ?? []])]
463
+ envVars: [...new Set([...hidden ? [] : [name], ...entry.envVars ?? []])]
454
464
  });
455
465
  return {
456
466
  ...docs,
467
+ ...bindings.length > 0 && { environmentBindings: bindings },
457
468
  fragments: docs.fragments.map((fragment) => fragment.type === "entry" ? {
458
469
  ...attach(fragment),
459
470
  type: "entry"
package/dist/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ import { HiddenVisibility } from "@optique/core/usage";
1
2
  import { SourceContext } from "@optique/core/context";
2
3
  import { FluentParser } from "@optique/core/fluent";
3
4
  import { Message } from "@optique/core/message";
@@ -126,6 +127,16 @@ declare function createEnvContext(options?: EnvContextOptions): EnvContext;
126
127
  * @since 1.0.0
127
128
  */
128
129
  interface BindEnvOptions<M extends Mode, TValue> {
130
+ /**
131
+ * Environment purpose and visibility, independent of CLI descriptions.
132
+ * This cannot expose an enclosing hidden parser. A CLI-less custom parser
133
+ * must declare `DocFragments.sourceOnly` to receive an independent entry.
134
+ * @since 1.4.0
135
+ */
136
+ readonly documentation?: {
137
+ readonly description?: Message;
138
+ readonly hidden?: HiddenVisibility;
139
+ };
129
140
  /**
130
141
  * The environment context to read from.
131
142
  */
@@ -172,7 +183,8 @@ interface BindEnvOptions<M extends Mode, TValue> {
172
183
  * Since 1.4.0, visible documentation entries include the full environment
173
184
  * variable name in `DocEntry.envVars`. Set `showEnvironment` on the runner
174
185
  * or formatter to display these names without reading their values. Parsers
175
- * without documentation entries, such as `fail()`, have no automatic entry.
186
+ * with `sourceOnly` documentation, such as `fail()`, receive independent
187
+ * environment records. Use `documentation.description` for purpose text.
176
188
  *
177
189
  * @param parser Parser that reads CLI values.
178
190
  * @param options Environment binding options.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { HiddenVisibility } from "@optique/core/usage";
1
2
  import { FluentParser } from "@optique/core/fluent";
2
3
  import { Message } from "@optique/core/message";
3
4
  import { NonEmptyString, ValueParser } from "@optique/core/valueparser";
@@ -126,6 +127,16 @@ declare function createEnvContext(options?: EnvContextOptions): EnvContext;
126
127
  * @since 1.0.0
127
128
  */
128
129
  interface BindEnvOptions<M extends Mode, TValue> {
130
+ /**
131
+ * Environment purpose and visibility, independent of CLI descriptions.
132
+ * This cannot expose an enclosing hidden parser. A CLI-less custom parser
133
+ * must declare `DocFragments.sourceOnly` to receive an independent entry.
134
+ * @since 1.4.0
135
+ */
136
+ readonly documentation?: {
137
+ readonly description?: Message;
138
+ readonly hidden?: HiddenVisibility;
139
+ };
129
140
  /**
130
141
  * The environment context to read from.
131
142
  */
@@ -172,7 +183,8 @@ interface BindEnvOptions<M extends Mode, TValue> {
172
183
  * Since 1.4.0, visible documentation entries include the full environment
173
184
  * variable name in `DocEntry.envVars`. Set `showEnvironment` on the runner
174
185
  * or formatter to display these names without reading their values. Parsers
175
- * without documentation entries, such as `fail()`, have no automatic entry.
186
+ * with `sourceOnly` documentation, such as `fail()`, receive independent
187
+ * environment records. Use `documentation.description` for purpose text.
176
188
  *
177
189
  * @param parser Parser that reads CLI values.
178
190
  * @param options Environment binding options.
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { isDocEntryHidden } from "@optique/core/doc";
2
+ import { formatUsageTerm, isDocHidden } from "@optique/core/usage";
1
3
  import { readFileSync } from "node:fs";
2
4
  import { resolve } from "node:path";
3
5
  import { getAnnotations } from "@optique/core/annotations";
@@ -306,7 +308,8 @@ function createEnvContext(options = {}) {
306
308
  * Since 1.4.0, visible documentation entries include the full environment
307
309
  * variable name in `DocEntry.envVars`. Set `showEnvironment` on the runner
308
310
  * or formatter to display these names without reading their values. Parsers
309
- * without documentation entries, such as `fail()`, have no automatic entry.
311
+ * with `sourceOnly` documentation, such as `fail()`, receive independent
312
+ * environment records. Use `documentation.description` for purpose text.
310
313
  *
311
314
  * @param parser Parser that reads CLI values.
312
315
  * @param options Environment binding options.
@@ -425,12 +428,20 @@ function bindEnv(parser, options) {
425
428
  const defaultValue = upperDefaultValue ?? options.default;
426
429
  const docs = parser.getDocFragments(state, defaultValue);
427
430
  const name = `${options.context.prefix}${options.key}`;
431
+ const hidden = isDocHidden(options.documentation?.hidden);
432
+ const visibleEntry = docs.fragments.some((fragment) => (fragment.type === "entry" ? [fragment] : fragment.entries).some((entry) => !isDocEntryHidden(entry) && formatUsageTerm(entry.term, { context: "doc" }).trim() !== ""));
433
+ const ownBindings = docs.sourceOnly === true || (options.documentation?.description?.length ?? 0) > 0 && visibleEntry ? [{
434
+ name,
435
+ ...options.documentation
436
+ }] : [];
437
+ const bindings = [...ownBindings, ...docs.environmentBindings ?? []];
428
438
  const attach = (entry) => ({
429
439
  ...entry,
430
- envVars: [...new Set([name, ...entry.envVars ?? []])]
440
+ envVars: [...new Set([...hidden ? [] : [name], ...entry.envVars ?? []])]
431
441
  });
432
442
  return {
433
443
  ...docs,
444
+ ...bindings.length > 0 && { environmentBindings: bindings },
434
445
  fragments: docs.fragments.map((fragment) => fragment.type === "entry" ? {
435
446
  ...attach(fragment),
436
447
  type: "entry"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/env",
3
- "version": "1.4.0-dev.2633",
3
+ "version": "1.4.0-dev.2636",
4
4
  "description": "Environment variable support for Optique",
5
5
  "keywords": [
6
6
  "CLI",
@@ -60,10 +60,10 @@
60
60
  },
61
61
  "sideEffects": false,
62
62
  "dependencies": {
63
- "@optique/core": "1.4.0-dev.2633+ee18a31e"
63
+ "@optique/core": "1.4.0-dev.2636+d5357098"
64
64
  },
65
65
  "devDependencies": {
66
- "@optique/config": "1.4.0-dev.2633+ee18a31e",
66
+ "@optique/config": "1.4.0-dev.2636+d5357098",
67
67
  "@types/node": "^24.0.0",
68
68
  "fast-check": "^4.7.0",
69
69
  "tsdown": "^0.13.0",