otp-wallet-cli
Version:
OTP Wallet CLI
57 lines (52 loc) • 1.43 kB
JavaScript
// Import.
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import chalk from 'chalk';
import { showCodes, addApp, deleteApp } from './app.js';
// Handle CLI commands.
const runCli = () => {
yargs(hideBin(process.argv))
.usage(`${chalk.bold.cyan('Usage:')} $0 <command> [options]`)
.command('show', chalk.yellow('Show all apps with OTP codes'), () => {}, showCodes)
.command(
'add <name> <secret>',
chalk.yellow('Add a new app'),
(yargs) => {
yargs
.positional('name', {
describe: 'App name',
type: 'string',
})
.positional('secret', {
describe: 'OTP secret',
type: 'string',
});
},
(argv) => addApp(argv.name, argv.secret),
)
.command(
'delete <name>',
chalk.yellow('Delete an app by name'),
(yargs) => {
yargs.positional('name', {
describe: 'App name',
type: 'string',
});
},
(argv) => deleteApp(argv.name),
)
.demandCommand(1, chalk.red.bold('You need at least one command before moving on.'))
.help()
.alias('help', 'h')
.version()
.alias('version', 'v')
.epilogue(
chalk.magentaBright(
'For more information, check out https://www.npmjs.com/package/otp-wallet-cli',
),
).argv;
};
runCli();
// Export.
export { runCli };