11import { getStorageConfig } from '@auth/provider.js' ;
22import { list , listBuckets } from '@tigrisdata/storage' ;
33import { exitWithError } from '@utils/exit.js' ;
4- import { formatOutput , formatSize } from '@utils/format.js' ;
5- import { getFormat , getOption } from '@utils/options.js' ;
4+ import { formatPaginatedOutput , formatSize } from '@utils/format.js' ;
5+ import { printPaginationHint } from '@utils/messages.js' ;
6+ import { getFormat , getOption , getPaginationOptions } from '@utils/options.js' ;
67import { parseAnyPath } from '@utils/path.js' ;
78
89export default async function ls ( options : Record < string , unknown > ) {
@@ -13,11 +14,16 @@ export default async function ls(options: Record<string, unknown>) {
1314 'snapshot' ,
1415 ] ) ;
1516 const format = getFormat ( options ) ;
17+ const { limit, pageToken } = getPaginationOptions ( options ) ;
1618
1719 if ( ! pathString ) {
1820 // No path provided, list all buckets
1921 const config = await getStorageConfig ( ) ;
20- const { data, error } = await listBuckets ( { config } ) ;
22+ const { data, error } = await listBuckets ( {
23+ ...( limit !== undefined ? { limit } : { } ) ,
24+ ...( pageToken ? { paginationToken : pageToken } : { } ) ,
25+ config,
26+ } ) ;
2127
2228 if ( error ) {
2329 exitWithError ( error ) ;
@@ -28,12 +34,28 @@ export default async function ls(options: Record<string, unknown>) {
2834 created : bucket . creationDate ,
2935 } ) ) ;
3036
31- const output = formatOutput ( buckets , format ! , 'buckets' , 'bucket' , [
37+ const columns = [
3238 { key : 'name' , header : 'Name' } ,
3339 { key : 'created' , header : 'Created' } ,
34- ] ) ;
40+ ] ;
41+
42+ const nextToken = data . paginationToken || undefined ;
43+
44+ const output = formatPaginatedOutput (
45+ buckets ,
46+ format ! ,
47+ 'buckets' ,
48+ 'bucket' ,
49+ columns ,
50+ { paginationToken : nextToken }
51+ ) ;
3552
3653 console . log ( output ) ;
54+
55+ if ( format !== 'json' && format !== 'xml' ) {
56+ printPaginationHint ( nextToken ) ;
57+ }
58+
3759 return ;
3860 }
3961
@@ -51,6 +73,8 @@ export default async function ls(options: Record<string, unknown>) {
5173 const { data, error } = await list ( {
5274 prefix,
5375 ...( snapshotVersion ? { snapshotVersion } : { } ) ,
76+ ...( limit !== undefined ? { limit } : { } ) ,
77+ ...( pageToken ? { paginationToken : pageToken } : { } ) ,
5478 config : {
5579 ...config ,
5680 bucket,
@@ -84,11 +108,26 @@ export default async function ls(options: Record<string, unknown>) {
84108 item . key !== '' && arr . findIndex ( ( i ) => i . key === item . key ) === index
85109 ) ;
86110
87- const output = formatOutput ( objects , format ! , 'objects' , 'object' , [
111+ const columns = [
88112 { key : 'key' , header : 'Key' } ,
89113 { key : 'size' , header : 'Size' } ,
90114 { key : 'modified' , header : 'Modified' } ,
91- ] ) ;
115+ ] ;
116+
117+ const nextToken = data . paginationToken || undefined ;
118+
119+ const output = formatPaginatedOutput (
120+ objects ,
121+ format ! ,
122+ 'objects' ,
123+ 'object' ,
124+ columns ,
125+ { paginationToken : nextToken }
126+ ) ;
92127
93128 console . log ( output ) ;
129+
130+ if ( format !== 'json' && format !== 'xml' ) {
131+ printPaginationHint ( nextToken ) ;
132+ }
94133}
0 commit comments