UNPKG

@stoar/cli

Version:

CLI tool for STOAR - decentralized file storage on Arweave

65 lines 2.27 kB
import { Command } from 'commander'; import { getConfig, setConfig, resetConfig } from '../utils/config.js'; import { output, success, info } from '../utils/output.js'; import { wrapCommand } from '../utils/error.js'; export const configCommand = new Command('config') .description('Manage CLI configuration'); configCommand .command('set') .description('Set a configuration value') .argument('<key>', 'Configuration key (e.g., gateway, walletPath)') .argument('<value>', 'Configuration value') .action(wrapCommand(async (key, value, _options, _command) => { // Parse value if it looks like JSON let parsedValue = value; if (value === 'true') parsedValue = true; else if (value === 'false') parsedValue = false; else if (!isNaN(Number(value))) parsedValue = Number(value); else if (value.startsWith('{') || value.startsWith('[')) { try { parsedValue = JSON.parse(value); } catch { // Keep as string if JSON parse fails } } setConfig(key, parsedValue); success(`Set ${key} = ${JSON.stringify(parsedValue)}`); })); configCommand .command('get') .description('Get a configuration value') .argument('[key]', 'Configuration key (omit to show all)') .action(wrapCommand(async (key, options, command) => { const globalOptions = command?.parent?.parent?.opts() || {}; const value = getConfig(key); if (value === undefined && key) { info(`No value set for ${key}`); return; } output(key ? value : value || {}, globalOptions); })); configCommand .command('reset') .description('Reset configuration to defaults') .action(wrapCommand(async () => { resetConfig(); success('Configuration reset to defaults'); })); configCommand .command('list') .description('List all configuration values') .action(wrapCommand(async (_options, command) => { const globalOptions = command.parent?.parent?.opts() || {}; const config = getConfig(); if (globalOptions.json) { output(config, globalOptions); return; } console.log('Current configuration:'); console.log(JSON.stringify(config, null, 2)); })); //# sourceMappingURL=config.js.map