git-mikado/src/git-mikado.js

80 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-10-24 17:40:34 +00:00
const yargs = require("yargs");
2021-11-01 14:27:55 +00:00
2021-11-19 00:54:41 +00:00
const newCommand = require("./commands/new");
2021-10-28 15:03:36 +00:00
const status = require("./commands/status");
2021-11-01 14:03:49 +00:00
const done = require("./commands/done");
const upstream = require("./commands/upstream");
2021-11-01 14:27:55 +00:00
2021-11-25 16:33:09 +00:00
const utils = require("./utils");
2021-11-01 14:03:49 +00:00
2021-11-25 16:33:09 +00:00
module.exports.run = async () => {
const currentBranch = await utils.currentBranch();
return yargs
2021-11-19 00:54:41 +00:00
.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", {
2021-11-01 14:03:49 +00:00
describe: "branch to mark as done",
default: currentBranch,
2021-11-19 00:54:41 +00:00
});
},
done
)
.command(
"upstream [upstream]",
"set an upstream of the current branch",
(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",
default: currentBranch,
describe:
"branch that is dependent on the new branch",
})
.demandOption(["branch"]);
},
newCommand
)
.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;
2021-11-25 16:33:09 +00:00
}