Skip to content

feat(UsageStrings): Add localisable labels record for usage rendering#303

Open
dimension-zero wants to merge 2 commits into
fsprojects:masterfrom
dimension-zero:pr/15-localisation-hooks
Open

feat(UsageStrings): Add localisable labels record for usage rendering#303
dimension-zero wants to merge 2 commits into
fsprojects:masterfrom
dimension-zero:pr/15-localisation-hooks

Conversation

@dimension-zero
Copy link
Copy Markdown
Contributor

feat(UsageStrings): Add localisable labels record for usage rendering

  • Types.fs: New public UsageStrings record carrying Usage, Options,
    Subcommands and SubcommandHelpHint. UsageStrings.Default returns the
    historical English labels.
  • UnParsers.fs: New mkUsageStringWithLabels that threads a UsageStrings
    through the renderer. Old mkUsageString kept as a thin forwarder using
    UsageStrings.Default, so all existing internal call sites are
    byte-identical.
  • ArgumentParser.fs: PrintUsage gains an optional ?usageStrings parameter
    defaulting to UsageStrings.Default. Existing signatures unchanged for
    positional callers (the new parameter is optional and appended last).

Additive only. The four hard-coded English labels are still emitted when
no UsageStrings is passed, preserving every existing rendered byte.


test(UsageStrings): Add coverage for localisation hooks

5 new tests:

  • UsageStrings.Default returns the historical English labels verbatim.
  • PrintUsage() with no override emits the English headers.
  • PrintUsage(usageStrings = french) emits the French headers and never
    the English ones.
  • SubcommandHelpHint default placeholder {0} / {1} interpolation is
    applied so the rendered hint shows 'myapp --help'.
  • A fully custom SubcommandHelpHint replaces the default hint line.

Net suite size on this branch: 112 -> 117.


* Types.fs: New public UsageStrings record carrying Usage, Options,
  Subcommands and SubcommandHelpHint. UsageStrings.Default returns the
  historical English labels.
* UnParsers.fs: New mkUsageStringWithLabels that threads a UsageStrings
  through the renderer. Old mkUsageString kept as a thin forwarder using
  UsageStrings.Default, so all existing internal call sites are
  byte-identical.
* ArgumentParser.fs: PrintUsage gains an optional ?usageStrings parameter
  defaulting to UsageStrings.Default. Existing signatures unchanged for
  positional callers (the new parameter is optional and appended last).

Additive only. The four hard-coded English labels are still emitted when
no UsageStrings is passed, preserving every existing rendered byte.
5 new tests:
* UsageStrings.Default returns the historical English labels verbatim.
* PrintUsage() with no override emits the English headers.
* PrintUsage(usageStrings = french) emits the French headers and never
  the English ones.
* SubcommandHelpHint default placeholder {0} / {1} interpolation is
  applied so the rendered hint shows 'myapp <subcommand> --help'.
* A fully custom SubcommandHelpHint replaces the default hint line.

Net suite size on this branch: 112 -> 117.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant