Skip to content

Commit

Permalink
#25: Stub out dynamic command selection and aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Sep 27, 2021
1 parent 87efca8 commit 69f27ab
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 122 deletions.
4 changes: 0 additions & 4 deletions cli/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ class UninstallCommand extends Command {
// static parserOptions
// static

static flags = {
name: flags.string({char: 'n', description: 'name to print'}),
}

async run() {
const {flags} = this.parse(UninstallCommand);
const name = flags.name || 'world';
Expand Down
6 changes: 1 addition & 5 deletions cli/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UninstallCommand extends Command {

static help = 'stuff';

static aliases = ['uninstall'];
// static aliases = ['uninstall'];

// static strict = false;
// static parse = true;
Expand All @@ -29,10 +29,6 @@ class UninstallCommand extends Command {
// static parserOptions
// static

static flags = {
name: flags.string({char: 'n', description: 'name to print'}),
}

async run() {
const {flags} = this.parse(UninstallCommand);
const name = flags.name || 'world';
Expand Down
35 changes: 35 additions & 0 deletions cli/commands/install-docker-desktop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const {Command, flags} = require('@oclif/command');

class InstallDockerDesktop extends Command {
// static _base = 'thing';
// static id = 'thing';
// static title = 'title';

static description = 'install docker desktop'

static hidden = true;

static usage = 'stuff';

static help = 'stuff';

static aliases = ['add'];

// static strict = false;
// static parse = true;
static flags = {
mem: flags.string({char: 'm', description: 'mem for vm'}),
}

// static args
// static plugin
// static examples
// static parserOptions
// static

async run() {
this.log('install docker-desktop');
}
}

module.exports = InstallDockerDesktop;
6 changes: 1 addition & 5 deletions cli/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UninstallCommand extends Command {

static help = 'stuff';

static aliases = ['uninstall'];
// static aliases = ['uninstall'];

// static strict = false;
// static parse = true;
Expand All @@ -29,10 +29,6 @@ class UninstallCommand extends Command {
// static parserOptions
// static

static flags = {
name: flags.string({char: 'n', description: 'name to print'}),
}

async run() {
const {flags} = this.parse(UninstallCommand);
const name = flags.name || 'world';
Expand Down
8 changes: 2 additions & 6 deletions cli/commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ class UninstallCommand extends Command {
// static parserOptions
// static

static flags = {
name: flags.string({char: 'n', description: 'name to print'}),
}

async run() {
const {flags} = this.parse(UninstallCommand);
const name = flags.name || 'world';
this.log(`hello ${name} from ./src/commands/hello.js`);
const name = flags.name || 'unin';
this.log(`erg ${name} from ./src/commands/hello.js`);
}
}

Expand Down
6 changes: 1 addition & 5 deletions cli/commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UninstallCommand extends Command {

static help = 'stuff';

static aliases = ['uninstall'];
// static aliases = ['uninstall'];

// static strict = false;
// static parse = true;
Expand All @@ -29,10 +29,6 @@ class UninstallCommand extends Command {
// static parserOptions
// static

static flags = {
name: flags.string({char: 'n', description: 'name to print'}),
}

async run() {
const {flags} = this.parse(UninstallCommand);
const name = flags.name || 'world';
Expand Down
35 changes: 35 additions & 0 deletions cli/commands/uninstall-docker-desktop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const {Command, flags} = require('@oclif/command');

class UninstallDockerDesktop extends Command {
// static _base = 'thing';
// static id = 'thing';
// static title = 'title';

static description = 'remove dd'

static hidden = true;

static usage = 'stuff';

static help = 'stuff';

static aliases = ['remove'];

// static strict = false;
// static parse = true;
static flags = {
purge: flags.string({char: 'p', description: 'blow it all up'}),
}

// static args
// static plugin
// static examples
// static parserOptions
// static

async run() {
this.log('unistnall docker-desktop');
}
}

module.exports = UninstallDockerDesktop;
1 change: 0 additions & 1 deletion cli/hooks/cnt.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

module.exports = async() => {};
104 changes: 104 additions & 0 deletions cli/hooks/init.ideas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// @NOTE: We use LET so we can rename the debugger as needed
const createDebugger = require('../../utils/debug');
const path = require('path');
const Ministrapper = require('../../utils/ministrapper');

module.exports = async({id, argv, config}) => {
let debug = createDebugger(config.dirname, 'hooks', 'init');
const sourceConfig = path.join(__dirname, '..', '..', 'config.yml');
const userConfig = path.join(config.configDir, 'config.yml');

// @TODO: set this based on some options (--debug?). if boolean/null should set * if string should set as if DEBUG
// envvar was set.
// @NOTE: this shows all debug right now for dev purposes. see @TODO above.
require('debug').enable('*'); // eslint-disable-line node/no-extraneous-require
debug('cli init start with id=%s, argv=%O', id, argv);

// if config cache exists then just load that and move on?

// Get config vars
const ENV_PREFIX = process.env.HYPERDRIVE_BOOTSTRAP_ENV_PREFIX || 'HYPERDRIVE';
const ENV_SEPARATOR = process.env.HYPERDRIVE_BOOTSTRAP_ENV_SEPARATOR || '_';

// Build up hyperdrive/product config from various sources
const bootstrapConf = new Ministrapper([config.name, 'utils', 'ministrapper']);

// @NOTE: do we want to accept some hidden args for this eg `hyperdrive --config bootstrap.module=something?`
// ENVARS are highest priority
bootstrapConf.env(ENV_PREFIX, ENV_SEPARATOR);
debug('get config from %s%s* envvars done', ENV_PREFIX, ENV_SEPARATOR);

// Then user config if it exists
bootstrapConf.file('user', {file: userConfig, format: require('nconf-yaml')});
debug('get config from file %s done', userConfig);

// Then source config
bootstrapConf.file('source', {file: sourceConfig, format: require('nconf-yaml')});
debug('get config from file %s done', sourceConfig);

// Then defaults
bootstrapConf.defaults({
product: 'hyperdrive',
mode: 'cli',
bootstrap: {
module: path.join(__dirname, '..', '..', 'utils', 'bootstrap.js'),
env: {
separator: '_',
prefix: 'HYPERDRIVE',
},
landoPlugins: true,
// @TODO: core plugin() below?
/*
plugins/core
plugins/
*/
plugins: [],
// @TODO:
pluginDirs: [],
},
});
debug('get config from defaults');

// @TODO: optionally add in lando plugin dirs?
// @NOTE: this will need to do a light lando bootstrap to get plugin dirs and such
// plugin manifests should be yaml eg dumpable to file

// Reset debugger to indicate product status
debug = createDebugger(bootstrapConf.get('product'), 'hooks', 'init');
debug('bootstrap config set to %O', bootstrapConf.get('source'));

// @TODO: load in oclif somewhere?
// leia: Object.prototype.hasOwnProperty.call(process.env, 'LEIA_PARSER_RUNNING'),
// packaged: Object.prototype.hasOwnProperty.call(process, 'pkg'),

// merge in some oclif stuff?

// 0. need to add plugins and plugin dirs to bootstrap config
// 1. Check if bootstrap exists, throw error if not
// 1. bootstrap hook?
// 2. run bootstrap
// * consolidate and organize plugins
// * external plugins
// * ./plugins
// * dataDir/plugins
// * build plugin manifest/registry
// * load plugins
// 3. hook?
// 4. merge into config?

// run bootstrap
// 1. merge in more config
// 2. go through plugins and build manifest of components/config/whatever
// 3. traverse plugins to find commands

// *. what do commandIDs do?
// *. install defaults eg desktop -> lando-desktop
/*
// commands = [require('./../more/bye')];
// config.plugins.push(new DynamicPlugin(config))
// console.log(config.plugins);
// config.plugins[0].commands[0].flags.stuff = flags.string({char: 'z', description: 'name to print'});
// console.log(id, argv, config); // {id, argv, conf}
*/
};
Loading

0 comments on commit 69f27ab

Please sign in to comment.