Description
The cp-deploy.sh script currently implements a CLI menu system based on SUBCOMMAND and ACTION with manual argument parsing. The current structure works but presents opportunities for improvement in maintainability, extensibility, and user experience.
Current State
- CLI menu with SUBCOMMAND → ACTION → OPTIONS structure
- Supported subcommands:
environment, vault, build, version, help
- Manual argument parsing via case statements (lines 457-542)
command_usage() function for general help (lines 7-100)
vault_usage() function for vault-specific help (line 316+)
- Parameter validation distributed across multiple script sections
Files Involved
cp-deploy.sh - Main script (1555 lines)
Identified Issues
- Maintainability: Parsing logic distributed across multiple sections (lines 455-1100+)
- Duplication: Repeated validations for each option
- Scalability: Adding new subcommands/actions requires changes in multiple locations
- Help Context: Help system not fully contextual for each action
- Error Handling: Error messages not always consistent
Refactoring Goals
Implementation Proposal
1. Modular Structure
# Separate functions for each subcommand
handle_environment_subcommand()
handle_vault_subcommand()
handle_build_subcommand()
# Validation functions
validate_environment_options()
validate_vault_options()
validate_common_options()
# Contextual help functions
show_environment_help()
show_vault_help()
show_action_help()
2. Configuration Table
Create a data structure (associative array) to define:
- Valid subcommands and their actions
- Required/optional options for each combination
- Specific help messages
3. Unified Parser
- Single entry point for parsing
- Centralized validation
- Consistent error handling
Description
The
cp-deploy.shscript currently implements a CLI menu system based on SUBCOMMAND and ACTION with manual argument parsing. The current structure works but presents opportunities for improvement in maintainability, extensibility, and user experience.Current State
environment,vault,build,version,helpcommand_usage()function for general help (lines 7-100)vault_usage()function for vault-specific help (line 316+)Files Involved
cp-deploy.sh- Main script (1555 lines)Identified Issues
Refactoring Goals
Implementation Proposal
1. Modular Structure
2. Configuration Table
Create a data structure (associative array) to define:
3. Unified Parser