Skip to content

Commit 25af532

Browse files
committed
fix: choice types
1 parent 5010099 commit 25af532

File tree

12 files changed

+403
-336
lines changed

12 files changed

+403
-336
lines changed

src/compose/get-options-variables.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { compact, intersection, keys } from 'lodash-es'
2-
import type { InputBooleanState } from '../input/boolean/types'
3-
import type { InputChoiceState } from '../input/choice/types'
2+
import type { InputBooleanStateInitial } from '../input/boolean/types'
3+
import type { InputChoiceStateInitial } from '../input/choice/types'
44
import type { InputCountState } from '../input/count/types'
55
import type { InputGroupState } from '../input/group/types'
66
import type { InputStringStateInitial } from '../input/string/types'
77
import { type GenericOption, type GenericVariable, InputType, type Match } from '../types'
88

99
export const getOptionsVariables = (
1010
state:
11-
| InputBooleanState
12-
| InputChoiceState
11+
| InputBooleanStateInitial
12+
| InputChoiceStateInitial
1313
| InputCountState
1414
| InputGroupState
1515
| InputStringStateInitial,

src/compose/placeholder-input-boolean.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
import type { FluentInterface, Model, Reducer } from '@escapace/fluent'
22
import { boolean } from '../input/boolean/domain-language'
33
import type {
4-
ActionDefault,
5-
ActionDescription,
6-
ActionOption,
7-
ActionReference,
8-
Settings,
4+
InputBooleanActionDefault,
5+
InputBooleanActionDescription,
6+
InputBooleanActionOption,
7+
InputBooleanActionReference,
8+
InputBooleanSettings,
99
} from '../input/boolean/types'
1010
import { PLACEHOLDER_REFERENCES } from '../types'
1111
import { extract } from '../utilities/extract'
1212

1313
export const placeholderInputHelpBoolean: FluentInterface<
1414
Model<
1515
Reducer<
16-
Settings,
16+
InputBooleanSettings,
1717
[
18-
ActionDefault<false>,
19-
ActionOption<'--help', undefined>,
20-
ActionOption<'-h', undefined>,
21-
ActionDescription,
22-
ActionReference<PLACEHOLDER_REFERENCES.HELP_BOOLEAN>,
18+
InputBooleanActionDefault<false>,
19+
InputBooleanActionOption<'--help', undefined>,
20+
InputBooleanActionOption<'-h', undefined>,
21+
InputBooleanActionDescription,
22+
InputBooleanActionReference<PLACEHOLDER_REFERENCES.HELP_BOOLEAN>,
2323
]
2424
>,
2525
[
26-
ActionDefault<false>,
27-
ActionOption<'--help', undefined>,
28-
ActionOption<'-h', undefined>,
29-
ActionDescription,
30-
ActionReference<PLACEHOLDER_REFERENCES.HELP_BOOLEAN>,
26+
InputBooleanActionDefault<false>,
27+
InputBooleanActionOption<'--help', undefined>,
28+
InputBooleanActionOption<'-h', undefined>,
29+
InputBooleanActionDescription,
30+
InputBooleanActionReference<PLACEHOLDER_REFERENCES.HELP_BOOLEAN>,
3131
]
3232
>
3333
> = extract(

src/index.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
1-
import { noop } from 'lodash-es'
2-
import { composeFactory } from './compose/compose-factory'
3-
41
export { command } from './command/domain-language'
5-
export type { CommandProperties as PropertiesCommand } from './command/types'
6-
72
export { boolean } from './input/boolean/domain-language'
8-
export type { PropertiesInputBoolean } from './input/boolean/types'
9-
103
export { choice } from './input/choice/domain-language'
11-
export type { PropertiesInputChoice } from './input/choice/types'
12-
134
export { count } from './input/count/domain-language'
14-
export type { PropertiesInputCount } from './input/count/types'
15-
165
export { group } from './input/group/domain-language'
17-
export type { PropertiesInputGroup } from './input/group/types'
18-
196
export { string } from './input/string/domain-language'
20-
export type { InputStringProperties as PropertiesInputString } from './input/string/types'
217

228
export type {
239
Compose,
@@ -29,6 +15,13 @@ export type {
2915
Settings,
3016
} from './types'
3117

18+
export type * from './command/types'
19+
export type * from './input/boolean/types'
20+
export type * from './input/choice/types'
21+
22+
import { noop } from 'lodash-es'
23+
import { composeFactory } from './compose/compose-factory'
24+
3225
export const compose = composeFactory({
3326
argv: __PLATFORM__ === 'node' ? process.argv.slice(2) : [],
3427
console,

src/input/boolean/domain-language.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { assert, describe, it } from 'vitest'
33
import { SYMBOL_INPUT_BOOLEAN } from '../../types'
44
import { boolean } from './domain-language'
55
import { reducer } from './reducer'
6-
import { TypeAction } from './types'
6+
import { InputBooleanTypeAction } from './types'
77

88
describe('input/boolean', () => {
99
it('domain-language', () => {
@@ -51,7 +51,7 @@ describe('input/boolean', () => {
5151
variables: [],
5252
})
5353

54-
assert.deepEqual(log(test1), [{ payload: reference, type: TypeAction.Reference }])
54+
assert.deepEqual(log(test1), [{ payload: reference, type: InputBooleanTypeAction.Reference }])
5555

5656
const test2 = test1.description('ABC')
5757

@@ -73,8 +73,8 @@ describe('input/boolean', () => {
7373
})
7474

7575
assert.deepEqual(log(test2), [
76-
{ payload: 'ABC', type: TypeAction.Description },
77-
{ payload: reference, type: TypeAction.Reference },
76+
{ payload: 'ABC', type: InputBooleanTypeAction.Description },
77+
{ payload: reference, type: InputBooleanTypeAction.Reference },
7878
])
7979

8080
const test3 = test2.variable('VARIABLE', 'NO_VARIABLE').option('--option', '--no-option')
@@ -108,17 +108,17 @@ describe('input/boolean', () => {
108108
false: '--no-option',
109109
true: '--option',
110110
},
111-
type: TypeAction.Option,
111+
type: InputBooleanTypeAction.Option,
112112
},
113113
{
114114
payload: {
115115
false: 'NO_VARIABLE',
116116
true: 'VARIABLE',
117117
},
118-
type: TypeAction.Variable,
118+
type: InputBooleanTypeAction.Variable,
119119
},
120-
{ payload: 'ABC', type: TypeAction.Description },
121-
{ payload: reference, type: TypeAction.Reference },
120+
{ payload: 'ABC', type: InputBooleanTypeAction.Description },
121+
{ payload: reference, type: InputBooleanTypeAction.Reference },
122122
])
123123

124124
const test4 = test3.default(false)
@@ -147,23 +147,23 @@ describe('input/boolean', () => {
147147
})
148148

149149
assert.deepEqual(log(test4), [
150-
{ payload: false, type: TypeAction.Default },
150+
{ payload: false, type: InputBooleanTypeAction.Default },
151151
{
152152
payload: {
153153
false: '--no-option',
154154
true: '--option',
155155
},
156-
type: TypeAction.Option,
156+
type: InputBooleanTypeAction.Option,
157157
},
158158
{
159159
payload: {
160160
false: 'NO_VARIABLE',
161161
true: 'VARIABLE',
162162
},
163-
type: TypeAction.Variable,
163+
type: InputBooleanTypeAction.Variable,
164164
},
165-
{ payload: 'ABC', type: TypeAction.Description },
166-
{ payload: reference, type: TypeAction.Reference },
165+
{ payload: 'ABC', type: InputBooleanTypeAction.Description },
166+
{ payload: reference, type: InputBooleanTypeAction.Reference },
167167
])
168168
})
169169
})

src/input/boolean/domain-language.ts

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,54 @@ import { type Reference, SYMBOL_INPUT_BOOLEAN } from '../../types'
55
import { assert } from '../../utilities/assert'
66
import { reducer } from './reducer'
77
import {
8-
type ActionDefault,
9-
type ActionDescription,
10-
type ActionOption,
11-
type ActionReference,
12-
type Actions,
13-
type ActionVariable,
14-
type Settings,
15-
type State,
16-
TypeAction,
8+
type InputBooleanActionDefault,
9+
type InputBooleanActionDescription,
10+
type InputBooleanActionOption,
11+
type InputBooleanActionReference,
12+
type InputBooleanActions,
13+
type InputBooleanActionVariable,
14+
type InputBooleanSettings,
15+
type InputBooleanState,
16+
InputBooleanTypeAction,
1717
} from './types'
1818

19-
const fluentReducer = (log: Actions): State => {
19+
const fluentReducer = (log: InputBooleanActions): InputBooleanState => {
2020
const reference = (
21-
find(log, (action) => action.type === TypeAction.Reference) as ActionReference | undefined
21+
find(log, (action) => action.type === InputBooleanTypeAction.Reference) as
22+
| InputBooleanActionReference
23+
| undefined
2224
)?.payload
2325

24-
const description = find(log, (action) => action.type === TypeAction.Description)?.payload
26+
const description = find(
27+
log,
28+
(action) => action.type === InputBooleanTypeAction.Description,
29+
)?.payload
2530

2631
const _default = (
27-
find(log, (action) => action.type === TypeAction.Default) as ActionDefault | undefined
32+
find(log, (action) => action.type === InputBooleanTypeAction.Default) as
33+
| InputBooleanActionDefault
34+
| undefined
2835
)?.payload
2936

3037
const isEmpty =
3138
log.length === 0 ||
32-
!some(log, (action) => action.type === TypeAction.Option || action.type === TypeAction.Variable)
39+
!some(
40+
log,
41+
(action) =>
42+
action.type === InputBooleanTypeAction.Option ||
43+
action.type === InputBooleanTypeAction.Variable,
44+
)
3345

3446
const rlog = reverse([...log])
3547

3648
const table = {
3749
options: assign(
3850
{},
3951
...map(
40-
filter(rlog, ({ type }) => type === TypeAction.Option) as ActionOption[],
52+
filter(
53+
rlog,
54+
({ type }) => type === InputBooleanTypeAction.Option,
55+
) as InputBooleanActionOption[],
4156
({ payload }): { [key: string]: boolean } =>
4257
assign(
4358
{},
@@ -49,7 +64,10 @@ const fluentReducer = (log: Actions): State => {
4964
variables: assign(
5065
{},
5166
...map(
52-
filter(rlog, ({ type }) => type === TypeAction.Variable) as ActionVariable[],
67+
filter(
68+
rlog,
69+
({ type }) => type === InputBooleanTypeAction.Variable,
70+
) as InputBooleanActionVariable[],
5371
({ payload }): { [key: string]: boolean } =>
5472
assign(
5573
{},
@@ -73,102 +91,104 @@ const fluentReducer = (log: Actions): State => {
7391
}
7492
}
7593

76-
export const boolean = builder<Settings>([
94+
export const boolean = builder<InputBooleanSettings>([
7795
{
7896
[Options.Interface]: (dispatch) => ({
7997
reference(reference: Reference) {
8098
assert.reference(reference)
8199

82-
return dispatch<ActionReference>({
100+
return dispatch<InputBooleanActionReference>({
83101
payload: reference,
84-
type: TypeAction.Reference,
102+
type: InputBooleanTypeAction.Reference,
85103
})
86104
},
87105
}),
88106
[Options.Keys]: ['reference'],
89107
[Options.Once]: true,
90108
[Options.Reducer]: fluentReducer,
91-
[Options.Type]: TypeAction.Reference,
109+
[Options.Type]: InputBooleanTypeAction.Reference,
92110
},
93111
{
94-
[Options.Dependencies]: [TypeAction.Reference],
112+
[Options.Dependencies]: [InputBooleanTypeAction.Reference],
95113
[Options.Interface]: (dispatch) => ({
96114
description(description: string) {
97115
assert.string(description)
98116

99-
return dispatch<ActionDescription>({
117+
return dispatch<InputBooleanActionDescription>({
100118
payload: description,
101-
type: TypeAction.Description,
119+
type: InputBooleanTypeAction.Description,
102120
})
103121
},
104122
}),
105123
[Options.Keys]: ['description'],
106124
[Options.Once]: true,
107125
[Options.Reducer]: fluentReducer,
108-
[Options.Type]: TypeAction.Description,
126+
[Options.Type]: InputBooleanTypeAction.Description,
109127
},
110128
{
111-
[Options.Conflicts]: [TypeAction.Default],
112-
[Options.Dependencies]: [TypeAction.Description],
129+
[Options.Conflicts]: [InputBooleanTypeAction.Default],
130+
[Options.Dependencies]: [InputBooleanTypeAction.Description],
113131
[Options.Interface]: (dispatch, _, state) => ({
114132
option(...value: [string | undefined, string | undefined]) {
115133
assert.inputDichotomousOption(value, state.options)
116134

117-
return dispatch<ActionOption>({
135+
return dispatch<InputBooleanActionOption>({
118136
payload: {
119137
false: value[1],
120138
true: value[0],
121139
},
122-
type: TypeAction.Option,
140+
type: InputBooleanTypeAction.Option,
123141
})
124142
},
125143
}),
126144
[Options.Keys]: ['option'],
127145
[Options.Once]: false,
128146
[Options.Reducer]: fluentReducer,
129-
[Options.Type]: TypeAction.Option,
147+
[Options.Type]: InputBooleanTypeAction.Option,
130148
},
131149
{
132-
[Options.Conflicts]: [TypeAction.Default],
133-
[Options.Dependencies]: [TypeAction.Description],
150+
[Options.Conflicts]: [InputBooleanTypeAction.Default],
151+
[Options.Dependencies]: [InputBooleanTypeAction.Description],
134152
[Options.Interface]: (dispatch, _, state) => ({
135153
variable(...value: [string | undefined, string | undefined]) {
136154
assert.inputBooleanVariable(value, state.variables)
137155

138-
return dispatch<ActionVariable>({
156+
return dispatch<InputBooleanActionVariable>({
139157
payload: {
140158
false: value[1],
141159
true: value[0],
142160
},
143-
type: TypeAction.Variable,
161+
type: InputBooleanTypeAction.Variable,
144162
})
145163
},
146164
}),
147165
[Options.Keys]: ['variable'],
148166
[Options.Once]: false,
149167
[Options.Reducer]: fluentReducer,
150-
[Options.Type]: TypeAction.Variable,
168+
[Options.Type]: InputBooleanTypeAction.Variable,
151169
},
152170
{
153-
[Options.Dependencies]: [TypeAction.Description],
171+
[Options.Dependencies]: [InputBooleanTypeAction.Description],
154172
[Options.Enabled]: (log) =>
155173
some(
156174
log,
157-
(action) => action.type === TypeAction.Option || action.type === TypeAction.Variable,
175+
(action) =>
176+
action.type === InputBooleanTypeAction.Option ||
177+
action.type === InputBooleanTypeAction.Variable,
158178
),
159179
[Options.Interface]: (dispatch) => ({
160180
default(value: boolean) {
161181
assert.boolean(value)
162182

163-
return dispatch<ActionDefault>({
183+
return dispatch<InputBooleanActionDefault>({
164184
payload: value,
165-
type: TypeAction.Default,
185+
type: InputBooleanTypeAction.Default,
166186
})
167187
},
168188
}),
169189
[Options.Keys]: ['default'],
170190
[Options.Once]: true,
171191
[Options.Reducer]: fluentReducer,
172-
[Options.Type]: TypeAction.Default,
192+
[Options.Type]: InputBooleanTypeAction.Default,
173193
},
174194
])

0 commit comments

Comments
 (0)