Skip to content

Commit 15177e3

Browse files
committed
feat: Command#versionOption
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 7929aac commit 15177e3

26 files changed

+339
-470
lines changed

README.md

Lines changed: 60 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
- [`Command#unknowns([strategy])`](#commandunknownsstrategy)
8484
- [`Command#usage([usage])`](#commandusageusage)
8585
- [`Command#version([version])`](#commandversionversion)
86+
- [`Command#versionOption([version])`](#commandversionoptionversion)
8687
- [`CommandEvent<T>(command)`](#commandeventtcommand)
8788
- [`CommandEvent#command`](#commandeventcommand)
8889
- [`CommandEvent#id`](#commandeventid)
@@ -135,8 +136,6 @@
135136
- [`Parseable#required`](#parseablerequired)
136137
- [`Parseable#toString()`](#parseabletostring)
137138
- [`Parseable#variadic`](#parseablevariadic)
138-
- [`VersionOption(info)`](#versionoptioninfo)
139-
- [`VersionOption#version`](#versionoptionversion)
140139
- [`keid`](#keid)
141140
- [`optionValueSource`](#optionvaluesource)
142141
- [Types](#types)
@@ -217,8 +216,7 @@
217216
- [`UnknownStrategy`](#unknownstrategy)
218217
- [`UsageData`](#usagedata)
219218
- [`UsageInfo`](#usageinfo)
220-
- [`VersionData`](#versiondata)
221-
- [`VersionOptionInfo`](#versionoptioninfo-1)
219+
- [`VersionOptionData`](#versionoptiondata)
222220
- [`Version`](#version)
223221
- [`WriteStream`](#writestream)
224222
- [`Write`](#write)
@@ -663,19 +661,18 @@ Create a new unattached option.
663661
##### Overloads
664662

665663
- `createOption(info: Flags | OptionInfo): Option`
666-
- `createOption(info: VersionOptionInfo): VersionOption`
667664
- `createOption(info: Flags, data?: OptionData | null | undefined): Option`
668665

669666
##### Parameters
670667

671-
- `info` ([`Flags`](#flags) | [`OptionInfo`](#optioninfo-1) | [`VersionOptionInfo`](#versionoptioninfo-1))
668+
- `info` ([`Flags`](#flags) | [`OptionInfo`](#optioninfo-1))
672669
— option info or flags
673670
- `data` ([`OptionData`](#optiondata))
674671
— additional option info
675672

676673
##### Returns
677674

678-
([`Option`](#optioninfo) | [`VersionOption`](#versionoptioninfo)) New option instance
675+
([`Option`](#optioninfo)) New option instance
679676

680677
#### `Command#default`
681678

@@ -903,6 +900,9 @@ Get the help text utility, configure the help text, or print the help text.
903900

904901
Get or configure the help subcommand.
905902

903+
> 👉 **Note**: No cleanup is performed when this method is called
904+
> with a different name (i.e. `help` as a string or `help.name`).
905+
906906
##### Overloads
907907

908908
- `helpCommand(help: HelpCommandData | null | undefined): this`
@@ -927,6 +927,9 @@ Get or configure the help subcommand.
927927

928928
Get or configure the help option.
929929

930+
> 👉 **Note**: No cleanup is performed when this method is called
931+
> with different flags (i.e. `help` as a string or `help.flags`).
932+
930933
##### Overloads
931934

932935
- `helpOption(help: HelpOptionData | null | undefined): this`
@@ -1284,33 +1287,55 @@ Get or set the command usage description.
12841287

12851288
#### `Command#version([version])`
12861289

1287-
Get or set the command version.
1288-
1289-
> 👉 **Note**: When setting the command version, this method auto-registers
1290-
> the version option with the flags `-v, --version`.
1291-
> No cleanup is performed when this method
1292-
> is called with different flags (i.e. `info` as a string or `info.flags`).
1290+
Get, set, or print the command version.
12931291

12941292
##### Overloads
12951293

1296-
- `version(version: VersionData | null | undefined): this`
1294+
- `version(version: Version | null | undefined): this`
12971295
- `version(version: true): undefined`
1298-
- `version<T extends string>(): T | null`
1296+
- `version<T extends Version>(): T | null`
12991297

13001298
##### Type Parameters
13011299

1302-
- `T` (`string`)
1300+
- `T` ([`Version`](#version))
13031301
— the command version
13041302

13051303
##### Parameters
13061304

1307-
- `version` ([`VersionData`](#versiondata) | `true` | `null`| `undefined`)
1308-
— the command version, version option instance, version option info, or `true` to print the command version
1305+
- `version` ([`Version`](#version) | `true` | `null`| `undefined`)
1306+
— the command version or `true` to print the command version
13091307

13101308
##### Returns
13111309

13121310
(`T` | [`this`](#commandinfo) | `null`) The command version or `this` command
13131311

1312+
#### `Command#versionOption([version])`
1313+
1314+
Get or configure the version option.
1315+
1316+
> 👉 **Note**: No cleanup is performed when this method is called
1317+
> with different flags (i.e. `version` as a string or `version.flags`).
1318+
1319+
##### Overloads
1320+
1321+
- `versionOption(version: VersionOptionData | null | undefined): this`
1322+
- `versionOption<T extends Option>(): T | null`
1323+
1324+
##### Type Parameters
1325+
1326+
- `T` ([`Option`](#optioninfo))
1327+
— the version option instance
1328+
1329+
##### Parameters
1330+
1331+
- `version` ([`VersionOptionData`](#versionoptiondata) | `null`| `undefined`)
1332+
— option flags, option instance, option info, `false` to disable the version option,
1333+
or any other allowed value to use the default configuration
1334+
1335+
##### Returns
1336+
1337+
(`T` | [`this`](#commandinfo) | `null`) Version option or `this` command
1338+
13141339
### `CommandEvent<T>(command)`
13151340

13161341
A parsed command event (`class`).
@@ -1896,25 +1921,6 @@ Get the candidate as a human-readable string (`abstract`).
18961921

18971922
Whether the candidate can be specified multiple times.
18981923

1899-
### `VersionOption(info)`
1900-
1901-
A command version option (`class`).
1902-
1903-
#### Extends
1904-
1905-
- [`Option`](#optioninfo)
1906-
1907-
#### Parameters
1908-
1909-
- `info` ([`Version`](#version) | [`VersionOptionInfo`](#versionoptioninfo-1))
1910-
— command version or option info
1911-
1912-
#### `VersionOption#version`
1913-
1914-
`string`
1915-
1916-
The version of the command.
1917-
19181924
### `keid`
19191925

19201926
Default error ids (`const enum`).
@@ -1934,6 +1940,7 @@ const enum keid {
19341940
missing_argument = 'kronk/missing-argument',
19351941
missing_mandatory_option = 'kronk/missing-mandatory-option',
19361942
no_flags = 'kronk/no-flags',
1943+
required_argument_after_optional = 'kronk/required-argument-after-optional',
19371944
unknown_implied_option = 'kronk/unknown-implied-option',
19381945
unknown_option = 'kronk/unknown-option'
19391946
}
@@ -2164,8 +2171,11 @@ Data transfer object for commands (TypeScript interface).
21642171
- `usage?` ([`UsageData`](#usagedata), optional)
21652172
— an object describing how the command is used
21662173
- default: `{ arguments: null, options: '[options]', subcommand: '[command]' }`
2167-
- `version?` ([`VersionData`](#versiondata), optional)
2168-
— command version configuration
2174+
- `version?` ([`Version`](#version), optional)
2175+
— the command version
2176+
- `versionOption?` ([`VersionOptionData`](#versionoptiondata), optional)
2177+
— customize the version option
2178+
- default: `{ description: 'print version number', flags: '-v, --version' }`
21692179
21702180
### `CommandErrorInfo`
21712181
@@ -2293,7 +2303,7 @@ Command metadata (TypeScript interface).
22932303
— the parent command
22942304
- `subcommands` ([`Map<string, Command>`](#commandinfo))
22952305
— map, where each key is the name of a subcommand each value is a subcommand
2296-
- `version` ([`VersionOption`](#versionoptioninfo) | `null` | `undefined`)
2306+
- `versionOption` ([`Option`](#optioninfo) | `null` | `undefined`)
22972307
— the version option
22982308
22992309
### `CommandName`
@@ -2486,14 +2496,13 @@ type HelpCommandData =
24862496
24872497
### `HelpOptionData`
24882498
2489-
Union of types used to configure the help option (TypeScript type).
2499+
Union of types used to configure the command help option (TypeScript type).
24902500
2491-
The command help option can be customized with
2492-
an [`Option`](#optioninfo) instance, [flags](#flags), or an [info object](#optioninfo-1).
2493-
It can also be disabled (`false`).
2501+
The help option can be customized with an [`Option`](#optioninfo) instance, [flags](#flags),
2502+
or an [info object](#optioninfo-1). It can also be disabled (`false`).
24942503
24952504
```ts
2496-
type HelpOptionData = Flags | Option | OptionInfo | OptionData | boolean
2505+
type HelpOptionData = Flags | Option | OptionData | OptionInfo | boolean
24972506
```
24982507
24992508
### `HelpTextOptions`
@@ -3219,30 +3228,17 @@ Command usage info (TypeScript interface).
32193228
— the descriptor
32203229
> 👉 **note**: displayed in auto-generated help text **only** when a command has at least one visible subcommand
32213230
3222-
### `VersionData`
3231+
### `VersionOptionData`
32233232
3224-
Union of types used to configure the version of a [`Command`](#commandinfo) (TypeScript type).
3233+
Union of types used to configure the command version option (TypeScript type).
3234+
3235+
The version option can be customized with an [`Option`](#optioninfo) instance, [flags](#flags),
3236+
or an [info object](#optioninfo-1). It can also be disabled (`false`).
32253237
32263238
```ts
3227-
type VersionData = Version | VersionOption | VersionOptionInfo
3239+
type VersionOptionData = Flags | Option | OptionData | OptionInfo | boolean
32283240
```
32293241
3230-
### `VersionOptionInfo`
3231-
3232-
Data used to create command version options (i.e. `-v, --version`) (TypeScript interface).
3233-
3234-
#### Extends
3235-
3236-
- [`OptionData`](#optiondata)
3237-
3238-
#### Properties
3239-
3240-
- `flags?` ([`Flags`](#flags), optional)
3241-
— option flags
3242-
- default: `'-v, --version'`
3243-
- `version` ([`Version`](#version))
3244-
— the command version
3245-
32463242
### `Version`
32473243
32483244
Union of command version types (TypeScript type).

__fixtures__/commands/clamp.mts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ export default {
4747
usage: {
4848
arguments: sfmt.required({ id: 'number' })
4949
},
50-
version: {
51-
flags: '-v --version',
52-
version: '1.0.0'
53-
}
50+
version: '1.0.0',
51+
versionOption: '-v --version'
5452
}

src/__snapshots__/index.e2e.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ exports[`e2e:kronk > should expose public api 1`] = `
1111
"Helpable",
1212
"Option",
1313
"Parseable",
14-
"VersionOption",
1514
"CommandError",
1615
"KronkError",
1716
"CommandEvent",

src/interfaces/__tests__/command.data.spec-d.mts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import type {
2323
SubcommandsData,
2424
UnknownStrategy,
2525
UsageData,
26-
VersionData
26+
Version,
27+
VersionOptionData
2728
} from '@flex-development/kronk'
2829
import type { Nilable, OptionalKeys } from '@flex-development/tutils'
2930

@@ -144,9 +145,15 @@ describe('unit-d:interfaces/CommandData', () => {
144145
.toEqualTypeOf<Nilable<UsageData>>()
145146
})
146147

147-
it('should match [version?: VersionData | null | undefined]', () => {
148+
it('should match [version?: Version | null | undefined]', () => {
148149
expectTypeOf<TestSubject>()
149150
.toHaveProperty('version')
150-
.toEqualTypeOf<Nilable<VersionData>>()
151+
.toEqualTypeOf<Nilable<Version>>()
152+
})
153+
154+
it('should match [versionOption?: VersionOptionData | null | undefined]', () => {
155+
expectTypeOf<TestSubject>()
156+
.toHaveProperty('versionOption')
157+
.toEqualTypeOf<Nilable<VersionOptionData>>()
151158
})
152159
})

src/interfaces/__tests__/command.metadata.spec-d.mts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import type {
1515
ExampleInfo,
1616
Help,
1717
HooksInfo,
18-
Option,
19-
VersionOption
18+
Option
2019
} from '@flex-development/kronk'
2120
import type { Nilable } from '@flex-development/tutils'
2221

@@ -95,9 +94,9 @@ describe('unit-d:interfaces/CommandMetadata', () => {
9594
.toEqualTypeOf<Map<string, Command>>()
9695
})
9796

98-
it('should match [version: VersionOption | null | undefined]', () => {
97+
it('should match [versionOption: Option | null | undefined]', () => {
9998
expectTypeOf<TestSubject>()
100-
.toHaveProperty('version')
101-
.toEqualTypeOf<Nilable<VersionOption>>()
99+
.toHaveProperty('versionOption')
100+
.toEqualTypeOf<Nilable<Option>>()
102101
})
103102
})

src/interfaces/__tests__/version-option.info.spec-d.mts

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/interfaces/command.data.mts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import type {
2121
SubcommandsData,
2222
UnknownStrategy,
2323
UsageData,
24-
VersionData
24+
Version,
25+
VersionOptionData
2526
} from '@flex-development/kronk'
2627

2728
/**
@@ -174,11 +175,21 @@ interface CommandData extends HelpableInfo {
174175
usage?: UsageData | null | undefined
175176

176177
/**
177-
* Command version configuration.
178+
* The command version.
178179
*
179-
* @see {@linkcode VersionData}
180+
* @see {@linkcode Version}
180181
*/
181-
version?: VersionData | null | undefined
182+
version?: Version | null | undefined
183+
184+
/**
185+
* Customize the version option.
186+
*
187+
* @see {@linkcode VersionOptionData}
188+
*
189+
* @default
190+
* { description: 'print version number', flags: '-v, --version' }
191+
*/
192+
versionOption?: VersionOptionData | null | undefined
182193
}
183194

184195
export type { CommandData as default }

0 commit comments

Comments
 (0)