Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github cli plugin issue #5 #10

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions githubCLI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { spawn } from "./helpers.ts";
import Plugin from "./plugin.ts";

class GithubCLI implements Plugin {
name = "gh";
commands: Record<string, (params: string[]) => Promise<void>>;

constructor() {
this.commands = {
pr: (args: string[]) => spawn(this.name, ["pr", ...args]),
repo: (args: string[]) => spawn(this.name, ["repo", ...args]),
issue: (args: string[]) => spawn(this.name, ["issue", ...args]),
gist: (args: string[]) => spawn(this.name, ["gist", ...args]),
auth: (args: string[]) => spawn(this.name, ["auth", ...args]),
help: () => {
console.log(`Common GitHub CLI Commands:
pr Work with pull requests
repo Create, clone, fork, and view repositories
issue Create and manage issues
gist Create gists
auth Authenticate and configure GitHub CLI`);
return Promise.resolve();
},
};
}

async evaluate(command: string): Promise<void> {
const [cmd, ...params] = command.split(" ");
if (this.commands[cmd]) {
await this.commands[cmd](params);
return;
}
if (cmd === "") {
return;
}
console.log("Command not found");
}
}

export default GithubCLI;
22 changes: 12 additions & 10 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Input } from "https://deno.land/x/cliffy@v1.0.0-rc.3/prompt/mod.ts";
import { green, cyan } from "https://deno.land/std@0.203.0/fmt/colors.ts";

import Docker from "./docker.ts";
import GithubCLI from "./githubCLI.ts";

const plugins = [new Docker()];
const plugins = [new Docker(), new GithubCLI()];

const history: string[] = [];

Expand Down Expand Up @@ -46,22 +47,23 @@ async function repl(
}

if (command.startsWith("use ")) {
const plugin = command.split(" ")[1];
if (plugins.find((p) => p.name === plugin)) {
const plugin = new Docker();
history.push(`use ${plugin.name}`);
const pluginName = command.split(" ")[1];
const selectedPlugin = plugins.find((p) => p.name === pluginName);
if (selectedPlugin) {
history.push(`use ${selectedPlugin.name}`);
repl(
plugin.name,
[...Object.keys(plugin.commands), ...history],
(command: string) => new Docker().evaluate(command)
selectedPlugin.name,
[...Object.keys(selectedPlugin.commands), ...history],
(command: string) => selectedPlugin.evaluate(command) // Step 3: Update Evaluation Logic
);
return;
} else {
console.log(`plugin ${green(plugin)} not found`);
console.log(`plugin ${green(pluginName)} not found`);
}
repl(message, suggestions, evaluate);
return;
}
}


if (evaluate) {
history.push(command);
Expand Down