Skip to content

Commit 94a1119

Browse files
amannirala13claude
andcommitted
feat(cli): implement config management CLI commands (Phase 4)
Add comprehensive config management commands with 7 subcommands for viewing, editing, validating, backing up, and migrating configurations. New Commands: - envg config get <key>: Get config value with dot notation support * Examples: envg config get package.name, envg config get environments.default * Returns formatted JSON for objects, plain values for primitives - envg config set <key> <value>: Set config value with dot notation * Auto-migrates v1→v2 before setting values * Updates metadata timestamps automatically * Type-safe value conversion (boolean, number, array, string) - envg config list: Display complete configuration as JSON * Works with both v1 and v2 configs * Pretty-printed output - envg config validate: Validate current configuration * Checks all required fields * Validates environment consistency (default must be in allowed list) * Provides detailed error messages for v2 configs - envg config backup: Create timestamped backup * Default path: .envguard/config.backup.{timestamp}.json * Custom path via --output flag - envg config restore <file>: Restore from backup * Auto-creates backup of current config before restoring * Validates backup file format * Supports both v1 and v2 backups - envg config migrate: Migrate v1→v2 manually * Auto-detects current version * Creates backup before migration * Skips if already v2 Implementation Details: - packages/cli/src/commands/config.action.ts: Core implementation (430 lines) * configGetAction: Nested object access with dot notation * configSetAction: Type-aware value setting with auto-migration * configListAction: Pretty JSON display * configValidateAction: Comprehensive validation with detailed errors * configBackupAction: Timestamped backup creation * configRestoreAction: Safe restore with auto-backup * configMigrateAction: v1→v2 migration workflow * Helper functions: getNestedValue(), setNestedValue() - packages/cli/src/cli.ts: Command registration * Registered config command with 7 subcommands * Commander.js subcommand pattern * Consistent --verbose flag support - packages/cli/src/commands/index.ts: Export config actions Features: - Dot notation for nested config access (e.g., "package.name", "environments.allowed") - Auto-migration from v1→v2 when setting values - Metadata tracking (lastModified, modifiedBy) - Safe restore with automatic backup creation - Type-safe value conversion (string→boolean/number/array) - Comprehensive validation with actionable error messages - Timestamped backups for audit trails CLI Help Output: $ envg config --help Usage: envg config [options] [command] Manage EnvGuard configuration Commands: get [options] <key> Get a config value (supports dot notation) set [options] <key> <value> Set a config value (supports dot notation) list [options] List all config values validate [options] Validate current config backup [options] Backup current config restore [options] <file> Restore config from backup migrate [options] Migrate config from v1 to v2 All Tests Passing: - @envguard/core: 58 tests - @envguard/node: 88 tests - @envguard/cli: 12 tests - Build: Clean for all packages 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d44c8d0 commit 94a1119

File tree

3 files changed

+541
-0
lines changed

3 files changed

+541
-0
lines changed

packages/cli/src/cli.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
import { program } from 'commander';
44
import {
55
checkAction,
6+
configBackupAction,
7+
configGetAction,
8+
configListAction,
9+
configMigrateAction,
10+
configRestoreAction,
11+
configSetAction,
12+
configValidateAction,
613
copyAction,
714
delAction,
815
editAction,
@@ -242,6 +249,69 @@ program
242249
}
243250
);
244251

252+
// Config command with subcommands
253+
const configCommand = program
254+
.command('config')
255+
.description('Manage EnvGuard configuration');
256+
257+
configCommand
258+
.command('get <key>')
259+
.description('Get a config value (supports dot notation)')
260+
.option('-v, --verbose', 'Enable verbose logging', false)
261+
.action(async (key: string, options) => {
262+
await configGetAction(key, options);
263+
});
264+
265+
configCommand
266+
.command('set <key> <value>')
267+
.description('Set a config value (supports dot notation)')
268+
.option('-v, --verbose', 'Enable verbose logging', false)
269+
.action(async (key: string, value: string, options) => {
270+
await configSetAction(key, value, options);
271+
});
272+
273+
configCommand
274+
.command('list')
275+
.description('List all config values')
276+
.option('-v, --verbose', 'Enable verbose logging', false)
277+
.action(async (options) => {
278+
await configListAction(options);
279+
});
280+
281+
configCommand
282+
.command('validate')
283+
.description('Validate current config')
284+
.option('-v, --verbose', 'Enable verbose logging', false)
285+
.action(async (options) => {
286+
await configValidateAction(options);
287+
});
288+
289+
configCommand
290+
.command('backup')
291+
.description('Backup current config')
292+
.option('-o, --output <path>', 'Output path for backup file')
293+
.option('-v, --verbose', 'Enable verbose logging', false)
294+
.action(async (options) => {
295+
await configBackupAction(options);
296+
});
297+
298+
configCommand
299+
.command('restore <file>')
300+
.description('Restore config from backup')
301+
.option('-v, --verbose', 'Enable verbose logging', false)
302+
.action(async (file: string, options) => {
303+
await configRestoreAction(file, options);
304+
});
305+
306+
configCommand
307+
.command('migrate')
308+
.description('Migrate config from v1 to v2')
309+
.option('--no-backup', 'Skip creating backup before migration')
310+
.option('-v, --verbose', 'Enable verbose logging', false)
311+
.action(async (options) => {
312+
await configMigrateAction(options);
313+
});
314+
245315
program
246316
.command('status')
247317
.description('Show current EnvGuard status and configuration')

0 commit comments

Comments
 (0)