Skip to content

Commit

Permalink
#25: Some useful but bad code
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Sep 21, 2021
1 parent 02f7f9b commit 25987b6
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 1 deletion.
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,22 @@
"license": "GPL-3.0",
"main": "src/index.js",
"oclif": {
"commands": "./src/commands",
"bin": "hyperdrive",
"commands": "./src/commands",
"hooks": {
"init": [
"./src/hooks/init.js"
],
"prerun": [
"./src/hooks/prerun.js"
],
"postrun": [
"./src/hooks/postrun.js"
],
"command_not_found": [
"./src/hooks/cnt.js"
]
},
"plugins": [
"@oclif/plugin-help"
]
Expand Down
22 changes: 22 additions & 0 deletions src/commands/bye.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const {Command, flags} = require('@oclif/command');

class GoodbyeCommand extends Command {
async run() {
const {flags} = this.parse(GoodbyeCommand);
const name = flags.name || 'world';
console.log(flags);
this.log(`goodbye ${name} from ./src/commands/hello.js`);
}
}
GoodbyeCommand.description = `awsgwag the command here
...
Extra documentation goes here
`;

GoodbyeCommand.flags = {
name: flags.string({char: 'q', description: 'name to print'}),
};

GoodbyeCommand.hidden = true;

module.exports = GoodbyeCommand;
1 change: 1 addition & 0 deletions src/commands/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class HelloCommand extends Command {
async run() {
const {flags} = this.parse(HelloCommand);
const name = flags.name || 'world';
console.log(flags);
this.log(`hello ${name} from ./src/commands/hello.js`);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/cnt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = async options => {
console.log(`example cnt hook running before ${options.id}`)
}
95 changes: 95 additions & 0 deletions src/hooks/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const { Command } = require('@oclif/config');
const {flags} = require('@oclif/command');
const Config = require('@oclif/config');

class DynamicPlugin extends Config.Plugin {
get hooks() { return {} }
get topics() {
return []
}
get commandIDs() {
return ['mydynamiccommand']
}

get commands() {
const cmd = require('./../more/bye');
cmd.id = 'bye';
cmd.load = () => cmd;
return [cmd];
}
}

/*
* New plugin types:
* HyperdrivePlugin extends Config.Plugin
* 1. accepts a list of commands and an optional selector function for a "parent"
*
*
*/

module.exports = async (options) => {
// 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(options); // {id, argv, conf}

// Set DEBUG=* when -vvv is set?

// Load in bootstrap config from configDir
/*
bootstrap:
bootstrapper: ./lib/bootstrap.js
envPrefix:
- HYPERDRIVE_
configSources:
- config.yml
mode: 'cli',
packaged: _.has(process, 'pkg'),
channel: stable?
leia: _.has(process, 'env.LEIA_PARSER_RUNNING')
pluginDirs: _.compact(pluginDirs.concat(process.landoAppPluginDirs))
plugins: ,
product: 'lando',
userAgent: `Lando/${version}`,
//
channel: 'stable',
landoFile: '.lando.yml',
logLevelConsole: (this.argv().verbose) ? this.argv().verbose + 1 : this.logLevel,
logDir: path.join(this.userConfRoot, 'logs'),
mode: 'cli',
packaged: _.has(process, 'pkg'),
pluginDirs: _.compact(pluginDirs.concat(process.landoAppPluginDirs)),
preLandoFiles: ['.lando.base.yml', '.lando.dist.yml', '.lando.upstream.yml'],
postLandoFiles: ['.lando.local.yml'],
userConfRoot: this.userConfRoot,
version,
*/

// run bootstrap
// 1. merge in more config
// 2. go through plugins and build manifest of components/config/whatever
// 3. traverse plugins to find commands
// 4. what do commandIDs do?
// 5. install defaults eg desktop -> lando-desktop
/*
hyperdrive:
// list of installers
installers:
// Just OCLIF command objects, this is just a list of metadata
commands:
- {id: 'install', variant: 'lando-docker-engine', path: }
plugins:
- pathtofunction -> gets config and returns plugin
// Final mods to commands, useful to add more options/args etc
mods: (?)
- {id: 'install', path: }
*/
}
3 changes: 3 additions & 0 deletions src/hooks/postrun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = async options => {
console.log(`example postrun hook running before ${options.id}`)
}
11 changes: 11 additions & 0 deletions src/hooks/prerun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const _ = require('lodash');
const {flags} = require('@oclif/command');

module.exports = async options => {
// options.Command = require('./../commands/hello2');
// console.log(options);
// options.Command.flags.name2 = flags.string({char: 'z', description: 'name to print'}),


console.log(`example prerun hook running before ${options.id}`)
}
23 changes: 23 additions & 0 deletions src/more/bye.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const {Command, flags} = require('@oclif/command');

class GoodbyeCommand extends Command {
async run() {
const {flags} = this.parse(GoodbyeCommand);
const name = flags.name || 'world';
console.log(flags);
this.log(`FU ${name} from ./src/commands/hello.js`);
}
}
GoodbyeCommand.name = 'bye';
GoodbyeCommand.description = `awsgwag the command here
...
Extra documentation goes here
`;

GoodbyeCommand.flags = {
name: flags.string({char: 'q', description: 'name to print'}),
};

GoodbyeCommand.hidden = false;

module.exports = GoodbyeCommand;

0 comments on commit 25987b6

Please sign in to comment.