@@ -6,9 +6,16 @@ import { BUILTIN_OPTIONS } from "../../builtin-options.js";
6
6
7
7
export const GLOBAL_NAME_PADDING = 6 ;
8
8
9
+ interface ArgumentDescriptor {
10
+ name : string ;
11
+ description : string ;
12
+ type ?: ParameterType ;
13
+ isRequired ?: boolean ;
14
+ }
15
+
9
16
export function parseGlobalOptions (
10
17
globalOptionsMap : GlobalOptionsMap ,
11
- ) : Array < { name : string ; description : string } > {
18
+ ) : ArgumentDescriptor [ ] {
12
19
const formattedBuiltinOptions = BUILTIN_OPTIONS . map (
13
20
( { name, description } ) => ( {
14
21
name : formatOptionName ( name ) ,
@@ -27,8 +34,8 @@ export function parseGlobalOptions(
27
34
}
28
35
29
36
export function parseTasks ( taskMap : Map < string , Task > ) : {
30
- tasks : Array < { name : string ; description : string } > ;
31
- subtasks : Array < { name : string ; description : string } > ;
37
+ tasks : ArgumentDescriptor [ ] ;
38
+ subtasks : ArgumentDescriptor [ ] ;
32
39
} {
33
40
const tasks = [ ] ;
34
41
const subtasks = [ ] ;
@@ -46,9 +53,7 @@ export function parseTasks(taskMap: Map<string, Task>): {
46
53
return { tasks, subtasks } ;
47
54
}
48
55
49
- export function parseSubtasks (
50
- task : Task ,
51
- ) : Array < { name : string ; description : string } > {
56
+ export function parseSubtasks ( task : Task ) : ArgumentDescriptor [ ] {
52
57
const subtasks = [ ] ;
53
58
54
59
for ( const [ , subtask ] of task . subtasks ) {
@@ -62,12 +67,8 @@ export function parseSubtasks(
62
67
}
63
68
64
69
export function parseOptions ( task : Task ) : {
65
- options : Array < { name : string ; description : string ; type : ParameterType } > ;
66
- positionalArguments : Array < {
67
- name : string ;
68
- description : string ;
69
- isRequired : boolean ;
70
- } > ;
70
+ options : ArgumentDescriptor [ ] ;
71
+ positionalArguments : ArgumentDescriptor [ ] ;
71
72
} {
72
73
const options = [ ] ;
73
74
const positionalArguments = [ ] ;
@@ -108,7 +109,7 @@ export function getLongestNameLength(tasks: Array<{ name: string }>): number {
108
109
109
110
export function getSection (
110
111
title : string ,
111
- items : Array < { name : string ; description : string } > ,
112
+ items : ArgumentDescriptor [ ] ,
112
113
namePadding : number ,
113
114
) : string {
114
115
return `\n${ title } :\n\n${ items . map ( ( { name, description } ) => ` ${ name . padEnd ( namePadding ) } ${ description } ` ) . join ( "\n" ) } \n` ;
@@ -126,7 +127,7 @@ export function getUsageString(
126
127
}
127
128
128
129
if ( positionalArguments . length > 0 ) {
129
- output += ` [--] ${ positionalArguments . map ( ( a ) => ( a . isRequired ? a . name : `[${ a . name } ]` ) ) . join ( " " ) } ` ;
130
+ output += ` [--] ${ positionalArguments . map ( ( a ) => ( a . isRequired === true ? a . name : `[${ a . name } ]` ) ) . join ( " " ) } ` ;
130
131
}
131
132
132
133
return output ;
0 commit comments