sui-direct
Version:
Decentralized version control system on SUI blockchain
99 lines (98 loc) • 4.54 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.repositoryCommands = repositoryCommands;
const auth_1 = __importDefault(require("../lib/auth"));
const remote_1 = __importDefault(require("../lib/remote"));
const colors_1 = require("../utils/colors");
const helpers_1 = require("../utils/helpers");
function repositoryCommands(program, p2p) {
const repo = program
.command("repository")
.aliases(["repo", "r"])
.description("Manage repositories released on sui.direct nodes.");
repo.command("list")
.description("List all repositories")
.action(() => {
(0, helpers_1.p2pStarter)(p2p).then(_ => {
const authInstance = new auth_1.default(_);
authInstance.getUser()
.then(async (user) => {
const remote = new remote_1.default(_);
const list = await remote.list(user.data.publicKey);
console.log(colors_1.colorize.successIcon(`Successfully fetched ${list.length} repositories for user ${colors_1.colorize.highlight(user.data.publicKey)}.\n`));
for (const repo of list) {
console.log(`${colors_1.colorize.warning(repo.name)} - ${colors_1.colorize.highlight(repo.blobID)}`);
}
return process.exit(0);
})
.catch(error => {
if (error) {
console.log(colors_1.colorize.errorIcon("An error occurred."));
console.error(colors_1.colorize.error(error));
}
})
.finally(() => {
process.exit(1);
});
});
});
repo.command("rename")
.description("Rename a repository")
.option("--blob <string>", "Blob ID of the repository")
.option("--id <string>", "ID of the repository")
.option("-n, --name <string>", "New name for the repository")
.action(options => {
if (!options.name) {
console.log(colors_1.colorize.errorIcon(`Please provide a new name for the repository using ${colors_1.colorize.warning("-n")} or ${colors_1.colorize.warning("--name")} option.`));
}
if (!options.blob && !options.id) {
console.log(colors_1.colorize.errorIcon(`Please provide the blob ID or repository ID using ${colors_1.colorize.warning("--blob")} or ${colors_1.colorize.warning("--id")} option.`));
}
if (!options.name || (!options.blob && !options.id)) {
return process.exit(1);
}
(0, helpers_1.p2pStarter)(p2p).then(_ => {
const authInstance = new auth_1.default(_);
authInstance.getUser()
.then(async () => {
const remote = new remote_1.default(_);
remote
.rename(options.name, options.blob, options.id)
.then(() => {
console.log(colors_1.colorize.successIcon(`Successfully renamed the repository to ${colors_1.colorize.highlight(options.name)}.`));
})
.catch(error => {
if (error) {
console.log(colors_1.colorize.errorIcon("An error occurred."));
console.error(colors_1.colorize.error(error));
}
})
.finally(() => {
process.exit(0);
});
})
.catch(error => {
if (error) {
console.log(colors_1.colorize.errorIcon("An error occurred."));
console.error(colors_1.colorize.error(error));
}
})
.finally(() => {
process.exit(0);
});
});
});
repo.command("delete")
.description("Delete a repository")
.option("--blob <string>", "Blob ID of the repository")
.option("-n, --name <string>", "Name of the repository")
.action(options => {
if (!options.name || !options.blob) {
console.log(colors_1.colorize.errorIcon(`Please provide the name and blob ID of the repository using ${colors_1.colorize.warning("-n")} or ${colors_1.colorize.warning("--name")} and ${colors_1.colorize.warning("--blob")} options.`));
return;
}
});
}