Skip to content
Snippets Groups Projects
Verified Commit 90e59802 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

module instead of class

parent 1d08aa9f
No related branches found
No related tags found
1 merge request!8Draft: Resolve "Add bash completion helper function"
Pipeline #29337 passed
This commit is part of merge request !8. Comments created here will be created in the context of that merge request.
......@@ -9,7 +9,7 @@ import { stateConfigFile } from '../config/ConfigFiles';
import semver from 'semver/preload';
import { version } from '../config/Version';
import Config from '../config/Config';
import AutoCompletionHelper from '../helpers/AutoCompletionHelper';
import {getBashCompletion} from '../helpers/AutoCompletionHelper';
class CommanderApp {
......@@ -44,7 +44,7 @@ class CommanderApp {
this.registerCommands();
AutoCompletionHelper.getBashCompletion(this.program)
getBashCompletion(this.program)
// AutoCompletionHelper.getCommands(this.program)
this.program.parse();
......
import { Command } from 'commander';
interface Node {
readonly name: string;
readonly children: Array<Node>;
......@@ -59,8 +60,7 @@ function flatten(tree: Node): Node[] {
}
class AutoCompletionHelper {
private printWordsGrandParents(cmd: Node) {
function printWordsGrandParents(cmd: Node) {
let prefix = ""
if (cmd.parent !== undefined) {
console.log(" case \"${grand_parent}\" in")
......@@ -77,12 +77,12 @@ class AutoCompletionHelper {
}
}
private buildCommandNode(root: Command): Node {
function buildCommandNode(root: Command): Node {
return createNode(root.name(), root.commands.map((sc) => getSubNode(sc, root)))
}
getBashCompletion(root: Command) {
const tree = this.buildCommandNode(root)
export function getBashCompletion(root: Command) {
const tree = buildCommandNode(root)
console.log("#/usr/bin/env bash")
console.log("function _dojo_completions()")
console.log("{")
......@@ -99,7 +99,7 @@ class AutoCompletionHelper {
const words = " words=\"" + cmd.children.map(c => c.name).join(" ") + "\""
console.log(words)
} else if (cmd != undefined && node.length > 1) {
node.forEach(n => this.printWordsGrandParents(n))
node.forEach(n => printWordsGrandParents(n))
}
console.log(" ;;")
}
......@@ -111,8 +111,3 @@ class AutoCompletionHelper {
console.log("}")
console.log("complete -F _dojo_completions dojo")
}
}
export default new AutoCompletionHelper();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment