Skip to content

[FEATURE] Implement "remove from file" CLI functionality #93

@Firstp1ck

Description

@Firstp1ck

Summary

The CLI currently accepts a --remove-from-file argument but doesn't implement the functionality (falls back to TUI with a warning). Implement the feature to allow removing packages listed in a file via command line, similar to the existing --install-from-file functionality.

Files to modify

  • src/args/definition.rs (around line 142 - replace TODO with implementation)
  • src/args/remove.rs (add handle_remove_from_file function)

Expected behavior

When users run pacsea --remove-from-file packages.txt:

  1. Read package names from the specified file (one package per line)
  2. Parse package names (handle comments, empty lines, whitespace)
  3. Display packages that will be removed
  4. Show appropriate warnings about package removal
  5. Prompt for user confirmation (defaulting to No for safety)
  6. Execute sudo pacman -Rns with the package list
  7. Show removal results and check for leftover config files
  8. Exit immediately (CLI mode, no TUI)

Implementation approach

  1. Add remove-from-file handler:

    pub fn handle_remove_from_file(file_path: &str) -> ! {
        // Read packages from file (reuse read_packages_from_file from install.rs)
        // Validate packages exist
        // Show removal preview
        // Get user confirmation
        // Execute removal
    }
  2. File parsing:

    • Reuse read_packages_from_file function from src/args/install.rs
    • Handle comments (lines starting with #)
    • Skip empty lines
    • Trim whitespace
  3. Package validation:

    • Check that packages are actually installed
    • Show warnings for packages that don't exist
  4. User interaction:

    • Display packages to be removed
    • Show removal warnings
    • Prompt for confirmation (default No)
    • Allow cancellation
  5. Execution:

    • Run sudo pacman -Rns command
    • Handle success/failure cases
    • Check for leftover config directories

Testing

  • cargo check passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • cargo test -- --test-threads=1 passes
  • Test reading packages from file with various formats
  • Test handling of comments and empty lines in file
  • Test validation of installed packages
  • Test user confirmation prompt (yes/no/cancel)
  • Test successful package removal
  • Test error handling when packages don't exist
  • Test config directory detection after removal
  • Test file not found error handling

Additional context

Follow the established patterns from:

  • File reading: read_packages_from_file in src/args/install.rs
  • CLI remove logic: handle_remove in src/args/remove.rs
  • User prompts: utils::prompt_user_no_default for safety
  • Error handling: Use existing i18n strings and tracing

The implementation should be consistent with --install-from-file behavior but follow remove-specific safety practices (confirmation defaults to No, clear warnings about data loss).

File format should match install-from-file:

# Package list for removal
package1
package2  # comment
# commented out package
package3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions