Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

Hard-coded timeout and verbosity values were duplicated across command handlers (Duration::from_secs(30) and VerbosityLevel::Normal appeared in 5 locations).

Changes

  • Created src/presentation/commands/constants.rs with:

    • DEFAULT_LOCK_TIMEOUT: 30-second timeout for repository file locks
    • DEFAULT_VERBOSITY: Normal verbosity level for user output
  • Updated command handlers to use constants:

    • create/subcommands/environment.rs
    • create/subcommands/template.rs
    • destroy/handler.rs

Before/After

// Before: Duplicate magic numbers
let repository_factory = RepositoryFactory::new(Duration::from_secs(30));
let mut output = UserOutput::new(VerbosityLevel::Normal);

// After: Centralized constants
use crate::presentation::commands::constants::{DEFAULT_LOCK_TIMEOUT, DEFAULT_VERBOSITY};

let repository_factory = RepositoryFactory::new(DEFAULT_LOCK_TIMEOUT);
let mut output = UserOutput::new(DEFAULT_VERBOSITY);

Configuration values are now discoverable in a single location with documented rationale.

Original prompt

This section details on the original issue you should resolve

<issue_title>Extract Command Configuration Constants</issue_title>
<issue_description>Parent Issue: #63
Type: 🎯 Quick Win
Impact: 🟢🟢 Medium
Effort: 🔵 Low
Priority: P0

Problem

Hard-coded magic numbers are scattered across command handlers:

// In create/subcommand.rs
let repository_factory = RepositoryFactory::new(Duration::from_secs(30));  // ❌ Magic number
let mut output = UserOutput::new(VerbosityLevel::Normal);                   // ❌ Hard-coded

// In destroy/command.rs
let repository_factory = RepositoryFactory::new(Duration::from_secs(30));  // ❌ Duplicate
let mut output = UserOutput::new(VerbosityLevel::Normal);                   // ❌ Duplicate

Proposed Solution

Create a constants module at src/presentation/commands/constants.rs:

//! Constants for command handlers

use std::time::Duration;
use crate::presentation::user_output::VerbosityLevel;

/// Default timeout for file lock operations in repository
pub const DEFAULT_LOCK_TIMEOUT: Duration = Duration::from_secs(30);

/// Default verbosity level for user output
pub const DEFAULT_VERBOSITY: VerbosityLevel = VerbosityLevel::Normal;

Then use in handlers:

use crate::presentation::commands::constants::{DEFAULT_LOCK_TIMEOUT, DEFAULT_VERBOSITY};

let repository_factory = RepositoryFactory::new(DEFAULT_LOCK_TIMEOUT);
let mut output = UserOutput::new(DEFAULT_VERBOSITY);

Benefits

  • ✅ Eliminates duplicate magic numbers
  • ✅ Makes configuration explicit and discoverable
  • ✅ Easier to adjust behavior without code changes
  • ✅ Better documentation for why specific values are used

Implementation Checklist

  • Create src/presentation/commands/constants.rs
  • Define DEFAULT_LOCK_TIMEOUT constant
  • Define DEFAULT_VERBOSITY constant
  • Add module documentation
  • Update src/presentation/commands/mod.rs to include module
  • Replace hard-coded values in create handler
  • Replace hard-coded values in destroy handler
  • Verify all tests pass
  • Run linter and fix any issues

Acceptance Criteria

  • Constants module exists with documented constants
  • All hard-coded timeout values use DEFAULT_LOCK_TIMEOUT
  • All hard-coded verbosity values use DEFAULT_VERBOSITY
  • No duplicate magic numbers in command handlers
  • All tests pass: cargo test presentation::commands
  • Pre-commit checks pass: ./scripts/pre-commit.sh
  • Code follows project conventions

Related Documentation

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@josecelano josecelano marked this pull request as ready for review October 29, 2025 08:35
Copilot AI changed the title [WIP] Extract command configuration constants to module Extract command configuration constants to eliminate duplicate magic numbers Oct 29, 2025
Copy link
Member

@josecelano josecelano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK beaf4fd

Copilot AI requested a review from josecelano October 29, 2025 08:36
Copilot finished work on behalf of josecelano October 29, 2025 08:36
@josecelano josecelano merged commit 09f16db into main Oct 29, 2025
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract Command Configuration Constants

2 participants