1- import { defineCommand , detectOutputFormat , listDatasets , type FlagsDef } from "bailian-cli-core" ;
2- import { emitResult , emitBare , emitRequestId , formatTable } from "bailian-cli-runtime" ;
1+ import { defineCommand , listDatasets , type FlagsDef } from "bailian-cli-core" ;
2+ import { emitResult , emitBare } from "bailian-cli-runtime" ;
33
44const LIST_FLAGS = {
55 page : { type : "number" , valueHint : "<n>" , description : "Page number (default: 1)" } ,
@@ -23,7 +23,6 @@ export default defineCommand({
2323 exampleArgs : [ "" , "--purpose fine-tune" , "--purpose evaluation --page-size 20" , "--output json" ] ,
2424 async run ( ctx ) {
2525 const { settings, flags } = ctx ;
26- const format = detectOutputFormat ( settings . output ) ;
2726
2827 if ( settings . dryRun ) {
2928 emitResult (
@@ -33,7 +32,7 @@ export default defineCommand({
3332 page_size : flags . pageSize ,
3433 purpose : flags . purpose ,
3534 } ,
36- format ,
35+ "json" ,
3736 ) ;
3837 return ;
3938 }
@@ -46,28 +45,17 @@ export default defineCommand({
4645 const files = response . data ?. files ?? [ ] ;
4746 const total = response . data ?. total ;
4847
49- // Normalize to consistent structure for both text/json output.
5048 const items = files . map ( ( item ) => ( {
5149 file_id : item . file_id ?? "" ,
5250 name : item . name ?? "" ,
5351 size : item . size !== undefined ? `${ ( item . size / 1024 ) . toFixed ( 1 ) } KB` : "?" ,
5452 purpose : item . purpose ?? "" ,
5553 } ) ) ;
5654
57- if ( format === "json" ) {
58- emitResult ( { items, total, request_id : response . request_id } , format ) ;
59- return ;
60- }
61-
62- // text / quiet
63- if ( items . length === 0 ) {
64- emitBare ( "No dataset files found." ) ;
65- return ;
55+ if ( settings . quiet ) {
56+ for ( const item of items ) emitBare ( item . file_id ) ;
57+ } else {
58+ emitResult ( { items, total, request_id : response . request_id } , "json" ) ;
6659 }
67- const headers = [ "FILE_ID" , "NAME" , "SIZE" , "PURPOSE" ] ;
68- const rows = items . map ( ( i ) => [ i . file_id , i . name , i . size , i . purpose ] ) ;
69- for ( const line of formatTable ( headers , rows ) ) emitBare ( line ) ;
70- if ( total !== undefined ) emitBare ( `\nTotal: ${ total } ` ) ;
71- emitRequestId ( response . request_id , settings . quiet ) ;
7260 } ,
7361} ) ;
0 commit comments