appcenter-cli
Version:
Command line tool for Visual Studio App Center
52 lines (41 loc) • 2.1 kB
text/typescript
import { Command, CommandResult, help, name, position, ErrorCodes, success, failure, shortName, longName, hasArg } from "../util/commandline";
import * as _ from "lodash";
import * as Path from "path";
import * as mkdirp from "mkdirp";
import * as Process from "process";
import { setupAutoCompleteForShell } from "../util/commandline/autocomplete";
import { out } from "../util/interaction";
export default class SetupAutoCompleteCommand extends Command {
private static readonly supportedShells = ["bash", "zsh", "fish"];
shell: string;
shellProfilePath: string;
async runNoClient(): Promise<CommandResult> {
if (_.isNil(this.shellProfilePath) && !_.isNil(this.shell)) {
return failure(ErrorCodes.InvalidParameter, "Shell should be specified only when shell profile path is specified");
}
if (!_.isNil(this.shell) && SetupAutoCompleteCommand.supportedShells.indexOf(this.shell) === -1) {
return failure(ErrorCodes.InvalidParameter, `${this.shell} is not supported. Only ${SetupAutoCompleteCommand.supportedShells.join(", ")} are supported`);
}
if (_.isNil(this.shell) && (!process.env.SHELL || !process.env.SHELL.match(SetupAutoCompleteCommand.supportedShells.join("|")))) {
return failure(ErrorCodes.InvalidParameter, "Current shell cannot be detected, please specify it explicitly");
}
if (!_.isNil(this.shellProfilePath)) {
mkdirp.sync(Path.dirname(this.shellProfilePath));
}
Process.on("exit", (code: number ) => {
if (code === 0) {
out.text("Please restart shell to apply changes");
}
});
setupAutoCompleteForShell(this.shellProfilePath, this.shell);
return success();
}
}