-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Problem
The main.rs file has grown to 1,589 lines and contains substantial command implementation logic that should be modularized. The execute_profile_command function alone spans ~660 lines (lines 755-1415), making main.rs harder to maintain and test.
Current State
File Size
main.rs: 1,589 lines
- execute_profile_command: ~660 lines (42% of file)
- execute_files_key_command: ~40 lines
- execute_api_command: ~20 lines
- Other command dispatchers and utilities
Already Modularized ✅
commands/api.rs- API commands properly extractedcommands/files_key.rs- Files.com key management extractedcommands/cloud/*- Cloud commands modularizedcommands/enterprise/*- Enterprise commands modularized
Still in main.rs ❌
- Profile commands - 660 lines of implementation in
execute_profile_command- List profiles with table/JSON formatting
- Show profile details
- Create/update profiles
- Remove profiles
- Set default profiles
- Validate configuration (newly added in UX improvements: Better error messages and command hints #259)
- Command dispatching logic
- Some workflow command handlers
Proposed Refactoring
Phase 1: Extract Profile Commands (High Priority)
Create commands/profile.rs following the existing pattern:
// commands/profile.rs
pub mod profile {
use crate::cli::{OutputFormat, ProfileCommands};
use crate::config::Config;
use crate::connection::ConnectionManager;
use crate::error::Result as CliResult;
pub async fn handle_profile_command(
profile_cmd: &ProfileCommands,
conn_mgr: &ConnectionManager,
output_format: OutputFormat,
) -> CliResult<()> {
match profile_cmd {
ProfileCommands::List => handle_list(conn_mgr, output_format).await,
ProfileCommands::Show { name } => handle_show(conn_mgr, name, output_format).await,
ProfileCommands::Set { .. } => handle_set(/* ... */).await,
ProfileCommands::Remove { name } => handle_remove(conn_mgr, name).await,
ProfileCommands::Validate => handle_validate(conn_mgr).await,
// ... other commands
}
}
async fn handle_list(
conn_mgr: &ConnectionManager,
output_format: OutputFormat,
) -> CliResult<()> {
// Move list implementation here (~100 lines)
}
async fn handle_validate(conn_mgr: &ConnectionManager) -> CliResult<()> {
// Move validate implementation here (~120 lines)
}
// ... other handler functions
}Update main.rs:
Commands::Profile(profile_cmd) => {
commands::profile::handle_profile_command(profile_cmd, &conn_mgr, cli.output).await?
}Phase 2: Simplify main.rs (Medium Priority)
After extracting profile commands, main.rs should focus on:
- CLI parsing and initialization
- Configuration loading
- Command routing/dispatching only
- Error handling at the top level
Target: < 300 lines for main.rs
Phase 3: Consider Additional Extractions (Low Priority)
- Move
format_command()to a telemetry/logging module - Extract workflow dispatchers to
commands/workflows.rs - Consider moving
init_tracing()to a separate module
Benefits
- Maintainability: Smaller, focused files easier to understand
- Testability: Profile commands can have unit tests in
commands/profile.rs - Consistency: Matches existing pattern (api.rs, files_key.rs)
- Separation of Concerns:
main.rsfocuses on application entry point - Easier Navigation: Developers can find profile logic in one place
Testing Requirements
- All existing tests must continue to pass
- Consider adding unit tests for individual profile handlers
- Integration tests should remain unchanged
Implementation Notes
- Follow the pattern established by
commands/api.rsandcommands/files_key.rs - Maintain all existing functionality - this is purely a code organization change
- No behavior changes - only code movement
- Keep public API surface minimal
Acceptance Criteria
-
commands/profile.rsmodule created with all profile command handlers -
main.rsreduced to < 500 lines (target: ~300) - All 67 tests still passing
- No clippy warnings
- Code formatted with
cargo fmt - Documentation updated if needed
Priority
Medium - This is technical debt cleanup that will improve maintainability but isn't blocking any features.
Related
- Similar to how
commands/api.rsandcommands/files_key.rswere already extracted - Part of ongoing code quality improvements
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request