1
+ const { CliUx, Flags} = require ( '@oclif/core' ) ;
1
2
const { BaseCommand} = require ( '../../lib/base-command' ) ;
2
- const { Flags} = require ( '@oclif/core' ) ;
3
3
4
4
class PluginInfo extends BaseCommand {
5
5
static description = 'shows plugin information' ;
@@ -19,37 +19,71 @@ class PluginInfo extends BaseCommand {
19
19
20
20
// @TODO : some sort of full flag?
21
21
static flags = {
22
+ all : Flags . boolean ( {
23
+ description : 'show all information' ,
24
+ default : false ,
25
+ } ) ,
22
26
...BaseCommand . globalFlags ,
23
27
} ;
24
28
25
29
async run ( ) {
26
- const _ = require ( 'lodash' ) ;
27
- const sortBy = require ( 'lodash/sortBy' ) ;
30
+ /*
31
+ // MVP plugin.yml
32
+ name: name,
33
+ description: info.description,
34
+ releaseNotesUrl: 'https://URL/to/CHANGELOG.yml',
35
+ // @todo : should we query for this?
36
+ // installedVersion: this.isInstalled ? this.version : 'Not Installed',
37
+ version: info.version,
38
+ repositoryUrl: info.repository,
39
+ author: info.author,
40
+ contributors: info.maintainers,
41
+ keywords: info.keywords,
42
+ };
43
+ */
44
+ // mods
45
+ const get = require ( 'lodash/get' ) ;
28
46
const prettify = require ( '../../../utils/prettify' ) ;
29
- const { CliUx} = require ( '@oclif/core' ) ;
30
-
31
- // get hyperdrive stuff
32
- const { hyperdrive} = this . config ;
33
- const Plugin = hyperdrive . Plugin ;
34
-
35
- const { args, flags} = await this . parse ( PluginInfo ) ;
36
- const data = await Plugin . info ( args . plugin ) ;
37
- if ( flags . json ) return data ;
38
-
39
- // Format data for table display.
40
- const tableKeys = hyperdrive . Config . keys ( data , { expandArrays : false } ) ;
41
-
42
- const rows = _ ( tableKeys )
43
- . filter ( path => _ . includes ( tableKeys , path ) )
44
- . map ( path => ( { key : path , value : _ . get ( data , path ) } ) )
45
- . value ( ) ;
46
-
47
- this . log ( ) ;
48
- CliUx . ux . table ( sortBy ( rows , 'key' ) , {
49
- key : { } ,
50
- value : { get : row => prettify ( row . value ) } ,
51
- } ) ;
52
- this . log ( ) ;
47
+ // get args and flags
48
+ const { argv, flags} = await this . parse ( PluginInfo ) ;
49
+ // get needed helpers things
50
+ const { hyperdrive, app, context} = this . config ;
51
+ // get the correct classes
52
+ const Plugin = context . app ? app . Plugin : hyperdrive . Plugin ;
53
+
54
+ // try to get the info
55
+ try {
56
+ const result = await Plugin . info ( argv [ 0 ] ) ;
57
+
58
+ // if this isnt all then truncate the info to the bare essentials
59
+ const info = flags . all ? result : {
60
+ name : result . name ,
61
+ description : result . description ,
62
+ version : result . version ,
63
+ author : result . author ,
64
+ contributors : result . maintainers ,
65
+ lando : result . lando ,
66
+ repository : result . repository ,
67
+ } ;
68
+
69
+ // if we have JSON then just return what we have
70
+ if ( flags . json ) return info ;
71
+
72
+ // otherwise construct some rows for tabular display
73
+ const Config = context . app ? app . Config : hyperdrive . Config ;
74
+ const rows = Config . keys ( info , { expandArrays : false } ) . map ( key => ( { key, value : get ( info , key ) } ) ) ;
75
+ // construct the column options
76
+ const columns = { key : { } , value : { get : row => prettify ( row . value ) } } ;
77
+
78
+ // print table
79
+ this . log ( ) ;
80
+ CliUx . ux . table ( rows , columns , { extended : flags . extended } ) ;
81
+ this . log ( ) ;
82
+
83
+ // if we cannot get info then throw an error here
84
+ } catch ( error ) {
85
+ this . error ( error ) ;
86
+ }
53
87
}
54
88
}
55
89
0 commit comments