UNPKG

sui-direct

Version:

Decentralized version control system on SUI blockchain

132 lines (131 loc) 5.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.vcsCommands = vcsCommands; const vcs_1 = __importDefault(require("../lib/vcs")); const auth_1 = __importDefault(require("../lib/auth")); const remote_1 = __importDefault(require("../lib/remote")); const bin_1 = require("../utils/bin"); const colors_1 = require("../utils/colors"); const helpers_1 = require("../utils/helpers"); function vcsCommands(program, p2p) { program .command("push") .description("Push changes to the remote repository") .action(async () => { if (!vcs_1.default.checkInitalized(process.cwd())) { console.log(colors_1.colorize.errorIcon("This directory is not a valid Direct VCS repository. Please initialize it first using `direct init`.")); return; } (0, helpers_1.p2pStarter)(p2p).then((_) => { const authInstance = new auth_1.default(_); authInstance.getUser() .then(async (user) => { const remote = new remote_1.default(_); await remote.push(process.cwd()); return process.exit(0); }) .catch(error => { console.error(colors_1.colorize.errorIcon("Failed to push changes")); if (error) console.error(colors_1.colorize.error(error)); }) .finally(() => { process.exit(1); }); }); }); program .command("pull") .description("Pull changes from the remote repository") .action(() => { }); program .command("clone") .description("Clone a remote repository") .option("-r, --id <string>", "Remote repository ID or blob ID") .action(options => { if (!options.id) { console.log(colors_1.colorize.errorIcon(`Please provide a repository ID or blob ID using ${colors_1.colorize.warning("-r")} or ${colors_1.colorize.warning("--id")} option.`)); return; } (0, helpers_1.p2pStarter)(p2p).then(async (_) => { const remote = new remote_1.default(_); await remote.clone(options.id); }); }); // direct-vcs commands /** * std::cout << "Usage: direct <command> [options]\n\n" << "Commands:\n" << " init Initialize a new repository\n" << " commit -m <message> Create a new commit\n" << " branch <name> Create a new branch\n" << " switch <branch> Switch to another branch\n" << " merge <branch> Merge specified branch into current branch\n" << " status Show current branch and status\n"; */ program .command("init") .description("Initialize a new repository") .action(() => { (0, bin_1.directVCS)("init"); process.exit(0); }); program .command("commit") .description("Create a new commit") .option("-m, --message <string>", "Commit message") .action(options => { if (!options.message) { console.log(colors_1.colorize.errorIcon(`Please provide a commit message using ${colors_1.colorize.warning("-m")} or ${colors_1.colorize.warning("--message")} option.`)); return; } (0, bin_1.directVCS)(`commit -m "${options.message}"`); process.exit(0); }); program .command("branch") .description("Create a new branch") .option("-n, --name <string>", "Name of the new branch") .action(options => { if (!options.name) { console.log(colors_1.colorize.errorIcon(`Please provide a name for the new branch using ${colors_1.colorize.warning("-n")} or ${colors_1.colorize.warning("--name")} option.`)); return; } (0, bin_1.directVCS)(`branch "${options.name}"`); process.exit(0); }); program .command("switch") .description("Switch to another branch") .option("-b, --branch <string>", "Name of the branch to switch to") .action(options => { if (!options.branch) { console.log(colors_1.colorize.errorIcon(`Please provide a branch name to switch to using ${colors_1.colorize.warning("-b")} or ${colors_1.colorize.warning("--branch")} option.`)); return; } (0, bin_1.directVCS)(`switch "${options.branch}"`); process.exit(0); }); program .command("merge") .description("Merge specified branch into current branch") .option("-b, --branch <string>", "Name of the branch to merge") .action(options => { if (!options.branch) { console.log(colors_1.colorize.errorIcon(`Please provide a branch name to merge using ${colors_1.colorize.warning("-b")} or ${colors_1.colorize.warning("--branch")} option.`)); return; } (0, bin_1.directVCS)(`merge "${options.branch}"`); process.exit(0); }); program .command("status") .description("Show current branch and status") .action(() => { (0, bin_1.directVCS)("status"); process.exit(0); }); }