@@ -22,9 +22,11 @@ export async function session() {
22
22
console . log ( await atcoder . checkSession ( ) ? "OK" : "not login" ) ;
23
23
}
24
24
25
- export async function contest ( contest_id : string | undefined , options : { id ?: boolean } ) {
25
+ export async function contest ( contest_id : string | undefined , options : { title ?: boolean , id ?: boolean , url ?: boolean } ) {
26
26
const f_id = options . id === true ;
27
- const format = ( { id, title, url} : Contest ) => formatAsShellOutput ( [ [ f_id ? SGR ( id , 37 ) : null , SGR ( title , 32 , 1 ) , url ] . filter ( e => e !== null ) as Array < string > ] ) ;
27
+ const f_title = options . title === true ;
28
+ const f_url = options . url === true ;
29
+ const format = ( { id, title, url} : Contest ) => formatAsShellOutput ( [ ( ( f_id || f_title || f_url ) ? [ f_id ? SGR ( id , 37 ) : null , SGR ( title , 32 , 1 ) , url ] . filter ( e => e !== null ) : [ SGR ( id , 37 ) , SGR ( title , 32 , 1 ) , url ] ) as Array < string > ] ) ;
28
30
if ( contest_id === undefined ) {
29
31
// idが与えられていない場合、プロジェクトファイルを探してコンテスト情報を表示
30
32
try {
@@ -46,9 +48,14 @@ export async function contest(contest_id: string | undefined, options: { id?: bo
46
48
}
47
49
}
48
50
49
- export async function task ( contest_id : string | undefined , task_id : string | undefined , options : { id ?: boolean } ) {
51
+ export async function task ( contest_id : string | undefined , task_id : string | undefined , options : { label ?: boolean , title ?: boolean , id ?: boolean , url ?: boolean } ) {
50
52
const f_id = options . id === true ;
51
- const format = ( { id, label, title, url} : Task ) => formatAsShellOutput ( [ [ f_id ? SGR ( id , 37 ) : null , SGR ( label , 32 ) , SGR ( title , 32 , 1 ) , url ] . filter ( e => e !== null ) as Array < string > ] ) ;
53
+ const f_title = options . title === true ;
54
+ const f_url = options . url === true ;
55
+ const f_label = options . label === true ;
56
+
57
+ //in case all flags are false (no print options specified), the hole (label, title, id, url string) is printed
58
+ const format = ( { id, label, title, url} : Task ) => formatAsShellOutput ( [ ( ( f_label || f_id || f_url || f_label ) ? [ f_label ? SGR ( label , 32 ) : null , f_title ? SGR ( title , 32 ) : null , f_id ? SGR ( id , 37 ) : null , f_url ? url : null ] . filter ( e => e !== null ) : [ SGR ( label , 32 ) , SGR ( title , 32 ) , SGR ( id , 37 ) , url ] ) as Array < string > ] ) ;
52
59
if ( contest_id === undefined && task_id === undefined ) {
53
60
// idが与えられていない場合、プロジェクトファイルを探す
54
61
try {
@@ -77,7 +84,7 @@ export async function task(contest_id: string | undefined, task_id: string | und
77
84
}
78
85
}
79
86
80
- export async function tasks ( contest_id : string | undefined , options : { id ?: boolean } ) {
87
+ export async function tasks ( contest_id : string | undefined , options : { id ?: boolean } ) {
81
88
const f_id = options . id === true ;
82
89
const format = ( tasks : Array < Task > ) => formatAsShellOutput ( tasks . map ( ( { id, label, title, url} ) => [ f_id ? SGR ( id , 37 ) : null , SGR ( label , 32 ) , SGR ( title , 32 , 1 ) , url ] . filter ( e => e !== null ) as Array < string > ) ) ;
83
90
if ( contest_id === undefined ) {
@@ -101,7 +108,7 @@ export async function tasks(contest_id: string | undefined, options: { id?: bool
101
108
}
102
109
}
103
110
104
- export async function url ( contest_id : string | undefined , task_id : string | undefined , options : { check ?: boolean } ) {
111
+ export async function url ( contest_id : string | undefined , task_id : string | undefined , options : { check ?: boolean } ) {
105
112
const f_check = options . check === true ;
106
113
if ( contest_id !== undefined && task_id !== undefined ) {
107
114
if ( f_check ) {
@@ -187,7 +194,7 @@ export async function format(format_string: string, contest_id: string, task_id?
187
194
}
188
195
}
189
196
190
- export async function submit ( filename : string | undefined , facade_options : Array < string > , options : { task ?: string , contest ?: string , skipFilename ?: boolean } ) {
197
+ export async function submit ( filename : string | undefined , facade_options : Array < string > , options : { task ?: string , contest ?: string , skipFilename ?: boolean } ) {
191
198
let contest_id = options . contest ;
192
199
let task_id = options . task ;
193
200
const f_skip_filename = options . skipFilename === true ;
@@ -246,7 +253,7 @@ export async function configDir() {
246
253
console . log ( await getConfigDirectory ( ) ) ;
247
254
}
248
255
249
- export async function config ( key : string | undefined , value : string | undefined , options : { D ?: boolean } ) {
256
+ export async function config ( key : string | undefined , value : string | undefined , options : { D ?: boolean } ) {
250
257
if ( options . D ) {
251
258
await deleteGlobalConfig ( key ) ;
252
259
}
@@ -338,7 +345,7 @@ async function getTemplateFromOption(template?: string | boolean): Promise<Templ
338
345
} ) ;
339
346
}
340
347
341
- export async function setup ( contest_id : string , options : { choice : Choices , force ?: boolean , contestDirnameFormat ?: string , taskDirnameFormat ?: string , template ?: string | boolean , tests ?: boolean } ) {
348
+ export async function setup ( contest_id : string , options : { choice : Choices , force ?: boolean , contestDirnameFormat ?: string , taskDirnameFormat ?: string , template ?: string | boolean , tests ?: boolean } ) {
342
349
try {
343
350
const template = await getTemplateFromOption ( options . template ) ;
344
351
const { contest} = await init ( contest_id , template , options ) ;
@@ -349,7 +356,7 @@ export async function setup(contest_id: string, options: { choice: Choices, forc
349
356
}
350
357
}
351
358
352
- export async function add ( options : { choice ?: Choices , force ?: boolean , taskDirnameFormat ?: string , template ?: string | boolean , tests ?: boolean } ) {
359
+ export async function add ( options : { choice ?: Choices , force ?: boolean , taskDirnameFormat ?: string , template ?: string | boolean , tests ?: boolean } ) {
353
360
try {
354
361
const { path, data} = await findProjectJSON ( ) ;
355
362
const { contest, tasks} = data ;
@@ -389,7 +396,7 @@ export async function add(options: { choice?: Choices, force?: boolean, taskDirn
389
396
}
390
397
}
391
398
392
- export async function selectTasks ( tasks : Array < Task > , choice : Choices , force : boolean = false ) : Promise < Array < { index : number , task : Task } > > {
399
+ export async function selectTasks ( tasks : Array < Task > , choice : Choices , force : boolean = false ) : Promise < Array < { index : number , task : Task } > > {
393
400
switch ( choice ) {
394
401
case "inquire" :
395
402
return await inquireTasks ( tasks , force ) ;
@@ -407,7 +414,7 @@ export async function selectTasks(tasks: Array<Task>, choice: Choices, force: bo
407
414
}
408
415
}
409
416
410
- export async function inquireTasks ( tasks : Array < Task > , force : boolean = false ) : Promise < Array < { index : number , task : Task } > > {
417
+ export async function inquireTasks ( tasks : Array < Task > , force : boolean = false ) : Promise < Array < { index : number , task : Task } > > {
411
418
const inquirer = await import ( "inquirer" ) ;
412
419
// まだディレクトリが作成されていない問題を一つだけ選択状態にしておく
413
420
const next = getNextTask2Install ( tasks ) ;
@@ -422,15 +429,15 @@ export async function inquireTasks(tasks: Array<Task>, force: boolean = false):
422
429
disabled : ! force && task . directory !== undefined ? ( ) => "already installed" : ( ) => false ,
423
430
checked : next !== null && index === next . index
424
431
} ) )
425
- } ] ) as { tasks : Array < { index : number , task : Task } > } ) . tasks ;
432
+ } ] ) as { tasks : Array < { index : number , task : Task } > } ) . tasks ;
426
433
}
427
434
428
435
/**
429
436
* まだディレクトリが作成されていない問題のうち、最も上のものを得る
430
437
* すべての問題のディレクトリが作成済みの場合はnullを返す
431
438
* @param tasks
432
439
*/
433
- function getNextTask2Install ( tasks : Array < Task > ) : { index : number , task : Task } | null {
440
+ function getNextTask2Install ( tasks : Array < Task > ) : { index : number , task : Task } | null {
434
441
for ( let i = 0 ; i < tasks . length ; i ++ ) {
435
442
if ( tasks [ i ] . directory === undefined ) {
436
443
return { index : i , task : tasks [ i ] } ;
0 commit comments