git-mikado/src/git-mikado.js

83 lines
2.1 KiB
JavaScript

const yargs = require("yargs");
const new_branch = require("./commands/new_branch");
const status = require("./commands/status");
const done = require("./commands/done");
const upstream = require("./commands/upstream");
const { currentBranch } = require('./utils');
currentBranch().then(
currentBranch => {
yargs
.scriptName("git-mikado")
.showHelpOnFail(true)
.command(
"status",
"show status of all mikado branches",
status
)
.command(
"done [branch]",
"set branch as done",
(yargs) => {
return yargs
.positional("branch", {
describe: "branch to mark as done",
default: currentBranch
})
},
done
)
.command(
"upstream [upstream]",
"set branch as done",
(yargs) => {
return yargs
.positional("upstream", {
describe: "upstream branch to add",
})
.option("branch", {
alias: "b",
describe: "target branch",
default: currentBranch,
})
.demandOption(["upstream"]);
},
upstream
)
.command(
"new [branch]",
"create new mikado branch",
(yargs) => {
return yargs
.positional("branch", {
describe: "name of the new branch",
})
.option("base", {
alias: "b",
describe: "base branch",
})
.option("upstream", {
alias: "u",
describe: "branch that is dependent on the new branch",
})
.demandOption(["branch"]);
},
new_branch
)
.fail((msg, err, yargs) => {
try {
const message = msg || err.message;
console.error(message);
process.exit(1);
} catch (e) {
yargs.showHelp();
}
})
.help()
.demandCommand(1, "")
.strict().argv;
});