1
- // import * as R from 'ramda'
2
- // import { parseISO } from 'date-fns'
3
- // import { parseJSON } from 'date-fns/fp'
4
-
5
- export function argsFromArgv ( argv : string [ ] ) : string [ ] {
6
- return argv . slice ( 2 ) // .filter((arg) => !(arg === '--'))
7
- }
8
1
9
2
enum TokenKind {
10
- Command = 'commands' ,
11
- Filter = 'filters' ,
3
+ Command = 'commands' ,
4
+ Filter = 'filters' ,
12
5
Modifier = 'modifiers' ,
13
- Ids = 'filters.ids' ,
6
+ Ids = 'filters.ids' ,
14
7
}
15
8
16
9
export type CommandConfig = {
17
- name : string
18
- aliases : string [ ]
19
- expect : TokenKind [ ]
20
- subcommands : CommandConfig [ ]
10
+ name : string
11
+ aliases : string [ ]
12
+ expect : TokenKind [ ]
13
+ subcommands : CommandConfig [ ]
21
14
confirmation ?: boolean
22
15
}
23
16
@@ -73,7 +66,6 @@ const CommandConfigs: CommandConfig[] = [
73
66
]
74
67
// no reason it should change
75
68
Object . freeze ( CommandConfigs )
76
- const defaultCommandName = 'list'
77
69
78
70
export type CommandConfigList = {
79
71
[ key : string ] : CommandConfig
@@ -84,15 +76,15 @@ export type TagSet = {
84
76
[ key : string ] : string [ ]
85
77
}
86
78
87
- // schema?
79
+ // should use a typebox schema?
88
80
export type ParsedCommandArgs = {
89
81
filters : {
90
- ids : number [ ]
91
- tags : TagSet
82
+ ids : number [ ]
83
+ tags : TagSet
92
84
words : string [ ]
93
85
}
94
86
modifiers : {
95
- tags : TagSet
87
+ tags : TagSet
96
88
words : string [ ]
97
89
}
98
90
}
@@ -116,12 +108,12 @@ function buildState(tokens: string[]): State {
116
108
command : [ ] ,
117
109
processedIndices : [ ] ,
118
110
filters : {
119
- ids : [ ] ,
120
- tags : { } ,
111
+ ids : [ ] ,
112
+ tags : { } ,
121
113
words : [ ] ,
122
114
} ,
123
115
modifiers : {
124
- tags : { } ,
116
+ tags : { } ,
125
117
words : [ ] ,
126
118
} ,
127
119
} as State
@@ -134,19 +126,20 @@ function extractCommand(state: State): ParsedCommand {
134
126
return parsed
135
127
}
136
128
129
+ const DefaultCommandName = 'list'
130
+
137
131
// https://taskwarrior.org/docs/syntax/
138
132
// task <filter> <command> <modifications> <miscellaneous>
139
-
133
+ //
140
134
// first, find the first thing that looks like a command
141
135
// everything before it is a filter (ids, etc)
142
136
// everything after it is a modification
143
-
144
137
export function parse ( tokens : string [ ] ) : ParsedCommand {
145
138
let state = buildState ( tokens )
146
139
state = parseCommands ( state )
147
140
148
141
if ( state . command . length === 0 )
149
- state . command . push ( defaultCommandName )
142
+ state . command . push ( DefaultCommandName )
150
143
151
144
// how we interpret remaining tokens depends on whether they're
152
145
// before or after a command
@@ -187,16 +180,14 @@ function parseCommands(state: State): State {
187
180
// we've previously found a command, but matched no valid subcommand
188
181
break
189
182
}
190
- return state // TODO rather than mutate the state, return an immutable update
183
+ return state // FIXME rather than mutate the state, return an immutable update
191
184
}
192
185
193
186
export function parseArgs ( argv : string [ ] ) : ParsedCommand {
194
187
return parse ( argsFromArgv ( argv ) )
195
188
}
196
189
197
- function commandAliases (
198
- cmds : CommandConfig [ ] = CommandConfigs ,
199
- ) : CommandConfigList {
190
+ function commandAliases ( cmds : CommandConfig [ ] = CommandConfigs ) : CommandConfigList {
200
191
const o : CommandConfigList = { }
201
192
cmds . map ( ( c ) =>
202
193
c . aliases . forEach ( ( alias ) => {
@@ -247,3 +238,11 @@ function recogniseIds(word: string): number[] | null {
247
238
}
248
239
249
240
// function recogniseTags()
241
+ // function recognisePriority()
242
+ // function recogniseParent()
243
+
244
+ // utility functions
245
+
246
+ export function argsFromArgv ( argv : string [ ] ) : string [ ] {
247
+ return argv . slice ( 2 ) // .filter((arg) => !(arg === '--'))
248
+ }
0 commit comments