1
1
/* eslint-disable no-console */
2
2
3
- // import chalk from 'chalk'
3
+ import chalk from 'chalk'
4
+ // @ts -ignore
5
+ import chalkTable from 'chalk-table'
4
6
import meow from 'meow'
5
7
import ora from 'ora'
6
8
@@ -20,7 +22,7 @@ export const dependencies = {
20
22
if ( input ) {
21
23
const spinnerText = 'Searching dependencies...'
22
24
const spinner = ora ( spinnerText ) . start ( )
23
- await searchDeps ( input . limit , input . offset , spinner )
25
+ await searchDeps ( input , spinner )
24
26
}
25
27
}
26
28
}
@@ -30,13 +32,13 @@ const dependenciesFlags = prepareFlags({
30
32
type : 'number' ,
31
33
shortFlag : 'l' ,
32
34
default : 50 ,
33
- description : 'Repository name ' ,
35
+ description : 'Maximum number of dependencies returned ' ,
34
36
} ,
35
37
offset : {
36
38
type : 'number' ,
37
39
shortFlag : 'o' ,
38
40
default : 0 ,
39
- description : 'Branch name ' ,
41
+ description : 'Page number ' ,
40
42
}
41
43
} )
42
44
@@ -71,7 +73,7 @@ function setupCommand (name, description, argv, importMeta) {
71
73
${ printFlagList ( flags , 6 ) }
72
74
73
75
Examples
74
- $ ${ name } FakeOrg
76
+ $ ${ name }
75
77
` , {
76
78
argv,
77
79
description,
@@ -106,12 +108,11 @@ function setupCommand (name, description, argv, importMeta) {
106
108
*/
107
109
108
110
/**
109
- * @param {number } limit
110
- * @param {number } offset
111
+ * @param {Command } input
111
112
* @param {import('ora').Ora } spinner
112
113
* @returns {Promise<void|DependenciesData> }
113
114
*/
114
- async function searchDeps ( limit , offset , spinner ) {
115
+ async function searchDeps ( { limit, offset, outputJson } , spinner ) {
115
116
const socketSdk = await setupSdk ( getDefaultKey ( ) )
116
117
// @ts -ignore
117
118
const result = await handleApiCall ( socketSdk . searchDependencies ( { limit, offset } ) , 'Searching dependencies' )
@@ -123,7 +124,32 @@ async function searchDeps (limit, offset, spinner) {
123
124
spinner . stop ( )
124
125
125
126
console . log ( 'Organization dependencies: \n' )
126
- console . log ( result . data )
127
+
128
+ if ( outputJson ) {
129
+ return console . log ( result . data )
130
+ }
131
+
132
+ const options = {
133
+ columns : [
134
+ { field : 'namespace' , name : chalk . cyan ( 'Namespace' ) } ,
135
+ { field : 'name' , name : chalk . cyan ( 'Name' ) } ,
136
+ { field : 'version' , name : chalk . cyan ( 'Version' ) } ,
137
+ { field : 'repository' , name : chalk . cyan ( 'Repository' ) } ,
138
+ { field : 'branch' , name : chalk . cyan ( 'Branch' ) } ,
139
+ { field : 'type' , name : chalk . cyan ( 'Type' ) } ,
140
+ { field : 'direct' , name : chalk . cyan ( 'Direct' ) }
141
+ ]
142
+ }
143
+
144
+ const formattedResults = result . data . rows . map ( ( /** @type {{[key:string]: any} } */ d ) => {
145
+ return {
146
+ ...d
147
+ }
148
+ } )
149
+
150
+ const table = chalkTable ( options , formattedResults )
151
+
152
+ console . log ( table , '\n' )
127
153
128
154
return {
129
155
data : result . data
0 commit comments