Skip to content

Refactor CLI Menu Structure in cp-deploy.sh #1094

@luigimolinaro

Description

@luigimolinaro

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

  1. Maintainability: Parsing logic distributed across multiple sections (lines 455-1100+)
  2. Duplication: Repeated validations for each option
  3. Scalability: Adding new subcommands/actions requires changes in multiple locations
  4. Help Context: Help system not fully contextual for each action
  5. Error Handling: Error messages not always consistent

Refactoring Goals

  • Modularize menu logic into separate, reusable functions
  • Centralize parameter validation
  • Improve contextual help system for each subcommand/action
  • Standardize error messages
  • Simplify adding new subcommands and actions
  • Maintain backward compatibility with existing commands

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions