Huge commit. Multiple fixes. Refactored commands. Invitations, resources, template inspection, mnemonic stuff, cli utils, pretty printing, remove unreserve on start, fix connectino requirement for invitations, format cashAddress to lockingBytecode on send, lots and lots of other stuff.
This commit is contained in:
73
src/cli/commands/mnemonic.ts
Normal file
73
src/cli/commands/mnemonic.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { bold, dim } from "../cli-utils.js";
|
||||
import { listMnemonicFiles, createMnemonicFile, createMnemonicSeed } from "../mnemonic.js";
|
||||
import type { CommandDependencies } from "./types.js";
|
||||
|
||||
/**
|
||||
* Prints the help message for the mnemonic command
|
||||
*/
|
||||
export const printMnemonicHelp = () => {
|
||||
console.log(
|
||||
`
|
||||
${bold("Usage:")} xo-cli mnemonic <sub-command>
|
||||
|
||||
${bold("Sub-commands:")}
|
||||
- create <mnemonic-seed> ${dim("Create a new mnemonic file")}
|
||||
- list ${dim("List all mnemonic files")}
|
||||
|
||||
${bold("Options:")}
|
||||
-o --output <output-filename> ${dim("Output filename for the mnemonic file")}
|
||||
-h --help ${dim("Show this help message")}
|
||||
`);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles the mnemonic command.
|
||||
* @param deps - The command dependencies.
|
||||
* @param args - Positional args after the command name, e.g. ["create"] or ["import", "page", "pencil", ...].
|
||||
* @param options - Parsed option flags, e.g. { output: "mnemonic.txt" }.
|
||||
*/
|
||||
export const handleMnemonicCommand = async (deps: Omit<CommandDependencies, "app">, args: string[], options: Record<string, string>): Promise<void> => {
|
||||
const subCommand = args[0];
|
||||
|
||||
if (!subCommand) {
|
||||
deps.verboseLogger("No sub-command provided");
|
||||
printMnemonicHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (subCommand) {
|
||||
case "create": {
|
||||
const mnemonicSeed = createMnemonicSeed();
|
||||
await createMnemonicFile(mnemonicSeed, options["output"]);
|
||||
|
||||
console.log(`Mnemonic file created: ${options["output"]} (${mnemonicSeed})`);
|
||||
break;
|
||||
}
|
||||
|
||||
case "import": {
|
||||
// The mnemonic seed words are all the positional args after the sub-command
|
||||
const mnemonicSeed = args.slice(1).join(" ");
|
||||
|
||||
if (!mnemonicSeed) {
|
||||
deps.verboseLogger("No mnemonic seed provided");
|
||||
printMnemonicHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
deps.verboseLogger(`Mnemonic seed: ${mnemonicSeed}`);
|
||||
await createMnemonicFile(mnemonicSeed, options["output"]);
|
||||
break;
|
||||
}
|
||||
|
||||
case "list": {
|
||||
const mnemonicFiles = listMnemonicFiles();
|
||||
console.log(mnemonicFiles.join('\n'));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
console.error(`Unknown sub-command: ${subCommand}`);
|
||||
printMnemonicHelp();
|
||||
return;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user