diff --git a/cli/commands/config.js b/cli/commands/config.js index 8760c22..2a223d1 100644 --- a/cli/commands/config.js +++ b/cli/commands/config.js @@ -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'; diff --git a/cli/commands/info.js b/cli/commands/info.js index 84d0bf9..2a223d1 100644 --- a/cli/commands/info.js +++ b/cli/commands/info.js @@ -15,7 +15,7 @@ class UninstallCommand extends Command { static help = 'stuff'; - static aliases = ['uninstall']; + // static aliases = ['uninstall']; // static strict = false; // static parse = true; @@ -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'; diff --git a/cli/commands/install-docker-desktop.js b/cli/commands/install-docker-desktop.js new file mode 100644 index 0000000..caee3f9 --- /dev/null +++ b/cli/commands/install-docker-desktop.js @@ -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; diff --git a/cli/commands/list.js b/cli/commands/list.js index 84d0bf9..2a223d1 100644 --- a/cli/commands/list.js +++ b/cli/commands/list.js @@ -15,7 +15,7 @@ class UninstallCommand extends Command { static help = 'stuff'; - static aliases = ['uninstall']; + // static aliases = ['uninstall']; // static strict = false; // static parse = true; @@ -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'; diff --git a/cli/commands/remove.js b/cli/commands/remove.js index 84d0bf9..2aa3f76 100644 --- a/cli/commands/remove.js +++ b/cli/commands/remove.js @@ -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`); } } diff --git a/cli/commands/status.js b/cli/commands/status.js index 84d0bf9..2a223d1 100644 --- a/cli/commands/status.js +++ b/cli/commands/status.js @@ -15,7 +15,7 @@ class UninstallCommand extends Command { static help = 'stuff'; - static aliases = ['uninstall']; + // static aliases = ['uninstall']; // static strict = false; // static parse = true; @@ -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'; diff --git a/cli/commands/uninstall-docker-desktop.js b/cli/commands/uninstall-docker-desktop.js new file mode 100644 index 0000000..72bd415 --- /dev/null +++ b/cli/commands/uninstall-docker-desktop.js @@ -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; diff --git a/cli/hooks/cnt.js b/cli/hooks/cnt.js index 5c05a01..61a4f97 100644 --- a/cli/hooks/cnt.js +++ b/cli/hooks/cnt.js @@ -1,2 +1 @@ - module.exports = async() => {}; diff --git a/cli/hooks/init.ideas.js b/cli/hooks/init.ideas.js new file mode 100644 index 0000000..3e55f96 --- /dev/null +++ b/cli/hooks/init.ideas.js @@ -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} + + */ +}; diff --git a/cli/hooks/init.js b/cli/hooks/init.js index bbc3559..cea5605 100644 --- a/cli/hooks/init.js +++ b/cli/hooks/init.js @@ -1,106 +1,67 @@ -'use strict'; - -// @NOTE: We use LET so we can rename the debugger as needed +const _ = require('lodash'); // eslint-disable-line node/no-unpublished-require const createDebugger = require('../../utils/debug'); -const path = require('path'); -const Ministrapper = require('../../utils/ministrapper'); +const Config = require('@oclif/config'); + +class DynamicPlugin extends Config.Plugin { + constructor(config, replace) { + super(config); + this.replace = replace; + } + + get hooks() { + return {}; + } + + get topics() { + return []; + } + + // @TODO: do we need this? + get commandIDs() { + return [this.replace.id]; + } + + get commands() { + const cmd = require(this.replace.path); + cmd.id = this.replace.id; + cmd.load = () => cmd; + return [cmd]; + } +} 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 + // 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} - - */ + // handle argv aliases + if ((id === 'install' || id === 'uninstall') && argv[0] === 'engine') { + argv[0] = 'docker-desktop'; + } + + // if id-argv matches a signature then remove id and load up queuer + // @NOTE: should this be both add and install? + if (id === 'install' && argv[0] === 'docker-desktop') { + // Lets remove the add command + const corePlugin = _.find(config.plugins, {name: '@lando/hyperdrive'}); + // delete corePlugin.manifest.commands.add; + _.remove(corePlugin.commands, {id: 'add'}); + // find the correct install plugin? + config.plugins.push(new DynamicPlugin(config, {id: 'install', path: './../commands/install-docker-desktop.js'})); + } + + // if id-argv matches a signature then remove id and load up queuer + // @NOTE: should this be both add and install? + if (id === 'uninstall' && argv[0] === 'docker-desktop') { + // Lets remove the add command + const corePlugin = _.find(config.plugins, {name: '@lando/hyperdrive'}); + // delete corePlugin.manifest.commands.add; + _.remove(corePlugin.commands, {id: 'remove'}); + // find the correct install plugin? + config.plugins.push(new DynamicPlugin(config, {id: 'uninstall', path: './../commands/uninstall-docker-desktop.js'})); + } }; diff --git a/cli/hooks/prerun.js b/cli/hooks/prerun.js index 5c05a01..61a4f97 100644 --- a/cli/hooks/prerun.js +++ b/cli/hooks/prerun.js @@ -1,2 +1 @@ - module.exports = async() => {};