Skip to content

Commit 1394f85

Browse files
committed
rework info command
1 parent 18ec531 commit 1394f85

File tree

4 files changed

+68
-29
lines changed

4 files changed

+68
-29
lines changed

cli/commands/info/index.js

+61-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
const {CliUx, Flags} = require('@oclif/core');
12
const {BaseCommand} = require('../../lib/base-command');
2-
const {Flags} = require('@oclif/core');
33

44
class PluginInfo extends BaseCommand {
55
static description = 'shows plugin information';
@@ -19,37 +19,71 @@ class PluginInfo extends BaseCommand {
1919

2020
// @TODO: some sort of full flag?
2121
static flags = {
22+
all: Flags.boolean({
23+
description: 'show all information',
24+
default: false,
25+
}),
2226
...BaseCommand.globalFlags,
2327
};
2428

2529
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');
2846
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+
}
5387
}
5488
}
5589

components/minapp.js

+2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ class MinApp {
5858
const mainfile = yaml.parse(fs.readFileSync(landofile, 'utf8'));
5959
this.name = slugify(mainfile.name, {lower: true, strict: true});
6060
this.root = path.dirname(landofile);
61+
Config.id = this.name;
6162
Plugin.id = this.name;
63+
this.Config = Config;
6264
this.Plugin = Plugin;
6365

6466
// set other props that are name-dependent

core/bootstrap.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ class Bootstrapper {
3636
this.registry = options.registry || {};
3737

3838
// add some helper classes
39+
Config.id = this.id;
3940
Plugin.id = this.id;
40-
this.Plugin = Plugin;
4141
this.Bootstrapper = Bootstrapper;
4242
this.Config = Config;
43+
this.Plugin = Plugin;
4344
}
4445

4546
// @TODO: the point of this is to have a high level way to "fetch" a certain kind of plugin eg global and

core/config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ nconf.formats.yaml = {
1818
* Creates a new Config instance.
1919
*/
2020
class Config extends nconf.Provider {
21+
static id = 'lando';
22+
2123
static keys(data, {prefix = '', expandArrays = true} = {}) {
2224
return require('../utils/get-object-keys')(data, {prefix, expandArrays});
2325
}
@@ -26,7 +28,7 @@ class Config extends nconf.Provider {
2628
// get parent stuff
2729
super();
2830
// get the id first since we need this for downstream things
29-
this.id = options.id || options.product || path.basename(process.argv[1]);
31+
this.id = options.id || options.product || path.basename(process.argv[1]) || Config.id;
3032
// properties
3133
this.managed = options.managed || 'managed';
3234
// namespaces utils

0 commit comments

Comments
 (0)