Skip to content

Extract verbosity filtering logic into dedicated VerbosityFilter struct#111

Merged
josecelano merged 3 commits into
mainfrom
copilot/fix-86304499-1048382931-6fbd7d64-ed0f-47f3-b203-d3d29face8f6
Nov 3, 2025
Merged

Extract verbosity filtering logic into dedicated VerbosityFilter struct#111
josecelano merged 3 commits into
mainfrom
copilot/fix-86304499-1048382931-6fbd7d64-ed0f-47f3-b203-d3d29face8f6

Conversation

Copilot AI commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Removes duplicated verbosity checks across UserOutput methods by extracting filtering logic into a private VerbosityFilter struct.

Before:

pub fn progress(&mut self, message: &str) {
    if self.verbosity >= VerbosityLevel::Normal {
        writeln!(self.stderr_writer, "⏳ {message}").ok();
    }
}

pub fn success(&mut self, message: &str) {
    if self.verbosity >= VerbosityLevel::Normal {
        writeln!(self.stderr_writer, "✅ {message}").ok();
    }
}

After:

struct VerbosityFilter {
    level: VerbosityLevel,
}

impl VerbosityFilter {
    fn should_show_progress(&self) -> bool {
        self.level >= VerbosityLevel::Normal
    }
}

pub fn progress(&mut self, message: &str) {
    if self.verbosity_filter.should_show_progress() {
        writeln!(self.stderr_writer, "⏳ {message}").ok();
    }
}

Changes

  • Created VerbosityFilter struct with convenience methods (should_show_progress(), should_show_errors(), etc.)
  • Replaced inline checks in 8 output methods with filter method calls
  • Added 16 unit tests covering all verbosity levels and edge cases
  • Public API unchanged - VerbosityFilter is module-private, users continue passing VerbosityLevel to constructors

Eliminates code duplication, makes verbosity rules independently testable, and provides a single point of control for filtering logic.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 192.0.2.1
    • Triggering command: ssh -i /nonexistent/key -p 22 -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null testuser@192.0.2.1 echo 'SSH connected' (packet block)
    • Triggering command: ssh -i /nonexistent/key -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5 testuser@192.0.2.1 echo 'SSH connected' (packet block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Extract Verbosity Filtering Logic</issue_title>
<issue_description># Extract Verbosity Filtering Logic

Issue: This issue
Parent Epic: #102 - User Output Architecture Improvements
Related: Refactoring Plan - Proposal torrust/torrust-tracker-deployer#0

Overview

Extract verbosity checking logic from UserOutput into a dedicated VerbosityFilter struct. This eliminates code duplication across all output methods and makes verbosity rules testable independently.

See detailed specification: docs/issues/extract-verbosity-filtering-logic.md (will be renamed after issue creation)

Implementation Plan

Phase 1: Create VerbosityFilter (30 minutes)

  • Create VerbosityFilter struct with level field
  • Implement new() constructor
  • Implement should_show() base method
  • Add convenience methods: should_show_progress(), should_show_errors(), etc.

Phase 2: Add Unit Tests (45 minutes)

  • Test should_show_progress() at different verbosity levels
  • Test should_show_errors() always returns true
  • Test general should_show() method
  • Verify edge cases and boundary conditions

Phase 3: Integrate with UserOutput (1 hour)

  • Replace verbosity: VerbosityLevel field with verbosity_filter: VerbosityFilter
  • Update UserOutput::new() constructor
  • Update UserOutput::with_writers() constructor
  • Update all output methods to use verbosity_filter.should_show_X()

Phase 4: Verify & Clean Up (30 minutes)

  • Run all existing tests and verify they pass
  • Run linters: cargo run --bin linter all
  • Review code for any remaining inline verbosity checks
  • Update module documentation if needed

Acceptance Criteria

Quality Checks:

  • Pre-commit checks pass: ./scripts/pre-commit.sh

Task-Specific Criteria:

  • VerbosityFilter struct created with all required methods
  • All inline verbosity checks replaced with filter method calls
  • Unit tests added for VerbosityFilter behavior
  • All existing tests still pass without modification
  • No breaking changes to public UserOutput API
  • Module documentation updated if needed

Estimated Time

Total: ~3 hours (conservative estimate with testing and verification)</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 3, 2025 14:17
Co-authored-by: josecelano <58816+josecelano@users.noreply.github.com>
Co-authored-by: josecelano <58816+josecelano@users.noreply.github.com>
Copilot AI changed the title [WIP] Extract Verbosity Filtering Logic Extract verbosity filtering logic into dedicated VerbosityFilter struct Nov 3, 2025
Copilot AI requested a review from josecelano November 3, 2025 14:42
@josecelano josecelano marked this pull request as ready for review November 3, 2025 18:52

@josecelano josecelano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK 046869f

@josecelano josecelano merged commit b3a8a85 into main Nov 3, 2025
51 checks passed
@josecelano josecelano deleted the copilot/fix-86304499-1048382931-6fbd7d64-ed0f-47f3-b203-d3d29face8f6 branch April 15, 2026 16:37
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 Verbosity Filtering Logic

2 participants