Skip to content

Fix CLI after PR #66: multi-word search, missing commands, terminal rendering#91

Merged
AdmGenSameer merged 4 commits into
mainfrom
copilot/fix-cli-bug-issues
Dec 9, 2025
Merged

Fix CLI after PR #66: multi-word search, missing commands, terminal rendering#91
AdmGenSameer merged 4 commits into
mainfrom
copilot/fix-cli-bug-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 9, 2025

Description

PR #66 introduced critical regressions: multi-word searches broke, three commands disappeared from CLI, and a 200-line argparse block conflicted with Typer implementation.

Related Issue

Issue details provided in problem statement.

Changes Made

Core Fixes

  • Fixed multi-word search: query: strquery: List[str] with space-join
  • Removed 200+ line argparse block (lines 601-803) causing parser conflicts
  • Added missing Typer commands: suggest, upgrade, web

UI Improvements

  • Added terminal width constraints (PANEL_PADDING constant) to all Rich tables/panels
  • Applied constraints to search, list-installed, and suggest module

Before:

@app.command()
def search(
    query: str = Argument(..., help="Name of the software to search for"),
    ...
) -> None:
    # Old argparse code mixed with Typer...
    parser = argparse.ArgumentParser(...)  # argparse not imported

After:

@app.command()
def search(
    query: List[str] = Argument(..., help="Name of the software to search for"),
    ...
) -> None:
    query_str = ' '.join(query)
    # Clean Typer-only implementation

Metrics

  • Removed: 296 lines broken code
  • Added: 113 lines clean implementation
  • Net: -183 lines

Screenshots or GIFs (if applicable)

Commands now in help:

╭─ Commands ───────────────────────────────────────────────────╮
│ search           Search for packages (multi-word supported)   │
│ suggest          Get app suggestions based on purpose         │
│ upgrade          Upgrade archpkg from GitHub                  │
│ web              Launch web interface                         │
│ update           Check/install package updates                │
│ config           Manage configuration                         │
│ list-installed   List tracked packages                        │
│ service          Manage background service                    │
╰──────────────────────────────────────────────────────────────╯

Checklist

  • Code is formatted with the project's Prettier config provided in .prettierrc (if present).
  • Only the necessary files are modified; no unrelated changes are included.
  • Follows clean code principles (readable, maintainable, minimal duplication).
  • All changes are clearly documented.
  • Code has been tested (manual/automated) and verified against edge cases.
  • No breaking changes are introduced to existing functionality.
  • All new and existing tests passed (if tests exist).

Additional Notes

Verified with CodeQL (0 vulnerabilities) and code review. Multi-word searches tested: archpkg search visual studio code, archpkg suggest video editing.

Original prompt

Critical Issues After PR #66 Merge

Multiple serious bugs were introduced after merging PR #66. The CLI is broken and needs comprehensive fixes.


Issue 1: Missing argparse Import

Error:

NameError: name 'argparse' is not defined

Location: archpkg/cli.py line 671

Fix: Add import argparse at the top of the file with other imports.


Issue 2: Multi-word Search Queries Broken

Error:

archpkg search jellyfin media player
Got unexpected extra arguments (media player)

Current code (line 586):

query: str = Argument(..., help="Name of the software to search for")

Fix: Change to accept multiple arguments and join them:

query: List[str] = Argument(..., help="Name of the software to search for")

Then join with spaces inside the function.


Issue 3: The search Command Has Broken/Duplicate Logic

The search command (starting at line 584) contains old argparse-based code mixed with new Typer code. Lines 601-803 contain a massive block of argparse code that:

  1. Creates an argparse.ArgumentParser (but argparse isn't imported)
  2. Duplicates functionality already handled by Typer
  3. References undefined variables

Fix: Remove the entire argparse block (lines 601-803) from the search command and implement proper Typer-based search logic.


Issue 4: Missing --web Command

The web interface was added (archpkg/web.py) but there's no command to launch it.

Fix: Add a new Typer command:

@app.command()
def web(
    port: int = Option(5000, "--port", "-p", help="Port to run the web server on"),
    host: str = Option("127.0.0.1", "--host", help="Host to bind the web server to"),
    debug: bool = Option(False, "--debug", help="Enable debug mode")
) -> None:
    """Launch the web interface for package management."""
    console.print(f"[blue]Starting web interface at http://{host}:{port}[/blue]")
    web_app.run(host=host, port=port, debug=debug)

Issue 5: Missing Commands in Help

The current --help only shows: search, update, config, list-installed, service

Missing commands that should be restored/added:


Issue 6: Terminal Box Rendering on Small Screens

Rich panels and tables break on smaller terminal windows.

Fix: Add console width detection and adjust output:

from rich.console import Console

console = Console(force_terminal=True)

# When creating tables/panels, add width constraints:
table = Table(title="...", width=min(console.width, 120), expand=False)

# For panels, use softwrap:
console.print(Panel(..., width=min(console.width - 4, 100)))

Issue 7: Orphaned else: Block (Syntax Error)

Lines 1047-1067 contain an orphaned else: block that causes a syntax error. This was identified earlier and needs to be removed.


Summary of Required Changes in archpkg/cli.py:

  1. Add missing import: import argparse at line 6 (or remove argparse usage entirely)
  2. Fix search command:
    • Accept List[str] for query to support multi-word searches
    • Remove the broken argparse block (lines 601-803)
    • Implement clean Typer-based search using existing helper functions
  3. Add suggest command: Restore the suggest functionality as a proper Typer command
  4. Add upgrade command: Restore as a proper Typer command
  5. Add web command: New command to launch Flask web interface
  6. Remove orphaned else: block: Delete lines 1047-1067
  7. Fix terminal width issues: Add width constraints to Rich tables and panels
  8. Ensure all original features work: The search, suggest, upgrade, cache management should all function

Reference: Original Working CLI Structure

The CLI should support these commands and options:

archpkg search <query>              # Search for packages (multi-word supported)
archpkg <query>                     # Shorthand for search (backward compat)
archpkg suggest <purpose>           # Get app suggestions
archpkg suggest --list              # List available purposes
archpkg upgrade                     # Upgrade archpkg from GitHub
archpkg web                         # Launch web interface
archpkg update                      # Check/install updates
archpkg config                      # Manage configuration
archpkg list-installed              # List tracked packages
archpkg service start|stop|status   # Manage background service

Global options:
--debug                             # Enable debug logging
--help                              # Show help
--cache-stats                       # Show cache statistics
--clear-cache [source]              # Clear cache
--aur                               # Prefer AUR p...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created as a result of the following prompt from Copilot chat.*
> ## Critical Issues After PR #66 Merge
> 
> Multiple serious bugs were introduced after merging PR #66. The CLI is broken and needs comprehensive fixes.
> 
> ---
> 
> ## Issue 1: Missing `argparse` Import
> 
> **Error:**
> ```
> NameError: name 'argparse' is not defined
> ```
> 
> **Location:** `archpkg/cli.py` line 671
> 
> **Fix:** Add `import argparse` at the top of the file with other imports.
> 
> ---
> 
> ## Issue 2: Multi-word Search Queries Broken
> 
> **Error:**
> ```
> archpkg search jellyfin media player
> Got unexpected extra arguments (media player)
> ```
> 
> **Current code (line 586):**
> ```python
> query: str = Argument(..., help="Name of the software to search for")
> ```
> 
> **Fix:** Change to accept multiple arguments and join them:
> ```python
> query: List[str] = Argument(..., help="Name of the software to search for")
> ```
> Then join with spaces inside the function.
> 
> ---
> 
> ## Issue 3: The `search` Command Has Broken/Duplicate Logic
> 
> The `search` command (starting at line 584) contains old argparse-based code mixed with new Typer code. Lines 601-803 contain a massive block of argparse code that:
> 1. Creates an `argparse.ArgumentParser` (but argparse isn't imported)
> 2. Duplicates functionality already handled by Typer
> 3. References undefined variables
> 
> **Fix:** Remove the entire argparse block (lines 601-803) from the `search` command and implement proper Typer-based search logic.
> 
> ---
> 
> ## Issue 4: Missing `--web` Command
> 
> The web interface was added (`archpkg/web.py`) but there's no command to launch it.
> 
> **Fix:** Add a new Typer command:
> ```python
> @app.command()
> def web(
>     port: int = Option(5000, "--port", "-p", help="Port to run the web server on"),
>     host: str = Option("127.0.0.1", "--host", help="Host to bind the web server to"),
>     debug: bool = Option(False, "--debug", help="Enable debug mode")
> ) -> None:
>     """Launch the web interface for package management."""
>     console.print(f"[blue]Starting web interface at http://{host}:{port}[/blue]")
>     web_app.run(host=host, port=port, debug=debug)
> ```
> 
> ---
> 
> ## Issue 5: Missing Commands in Help
> 
> The current `--help` only shows: `search`, `update`, `config`, `list-installed`, `service`
> 
> **Missing commands that should be restored/added:**
> - `suggest` - Get app suggestions based on purpose (was in original code)
> - `upgrade` - Upgrade archpkg from GitHub (was in original code)  
> - `web` - Launch web interface (new feature from PR #66)
> - `install` - Direct package installation (if it existed before)
> 
> ---
> 
> ## Issue 6: Terminal Box Rendering on Small Screens
> 
> Rich panels and tables break on smaller terminal windows.
> 
> **Fix:** Add console width detection and adjust output:
> ```python
> from rich.console import Console
> 
> console = Console(force_terminal=True)
> 
> # When creating tables/panels, add width constraints:
> table = Table(title="...", width=min(console.width, 120), expand=False)
> 
> # For panels, use softwrap:
> console.print(Panel(..., width=min(console.width - 4, 100)))
> ```
> 
> ---
> 
> ## Issue 7: Orphaned `else:` Block (Syntax Error)
> 
> Lines 1047-1067 contain an orphaned `else:` block that causes a syntax error. This was identified earlier and needs to be removed.
> 
> ---
> 
> ## Summary of Required Changes in `archpkg/cli.py`:
> 
> 1. **Add missing import:** `import argparse` at line 6 (or remove argparse usage entirely)
> 2. **Fix `search` command:** 
>    - Accept `List[str]` for query to support multi-word searches
>    - Remove the broken argparse block (lines 601-803)
>    - Implement clean Typer-based search using existing helper functions
> 3. **Add `suggest` command:** Restore the suggest functionality as a proper Typer command
> 4. **Add `upgrade` command:** Restore as a proper Typer command  
> 5. **Add `web` command:** New command to launch Flask web interface
> 6. **Remove orphaned `else:` block:** Delete lines 1047-1067
> 7. **Fix terminal width issues:** Add width constraints to Rich tables and panels
> 8. **Ensure all original features work:** The search, suggest, upgrade, cache management should all function
> 
> ---
> 
> ## Reference: Original Working CLI Structure
> 
> The CLI should support these commands and options:
> 
> ```
> archpkg search <query>              # Search for packages (multi-word supported)
> archpkg <query>                     # Shorthand for search (backward compat)
> archpkg suggest <purpose>           # Get app suggestions
> archpkg suggest --list              # List available purposes
> archpkg upgrade                     # Upgrade archpkg from GitHub
> archpkg web                         # Launch web interface
> archpkg update                      # Check/install updates
> archpkg config                      # Manage configuration
> archpkg list-installed              # List tracked packages
> archpkg service start|stop|status   # Manage background service
> 
> Global options:
> --debug                             # Enable debug logging
> --help                              # Show help
> --cache-stats                       # Show cache statistics
> --clear-cache [source]              # Clear cache
> --aur                               # Prefer AUR packages
> --no-cache                          # Skip cache
> ```

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 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](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 3 commits December 9, 2025 06:38
Co-authored-by: AdmGenSameer <154604600+AdmGenSameer@users.noreply.github.com>
Co-authored-by: AdmGenSameer <154604600+AdmGenSameer@users.noreply.github.com>
Co-authored-by: AdmGenSameer <154604600+AdmGenSameer@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix critical bugs introduced by PR #66 merge Fix CLI after PR #66: multi-word search, missing commands, terminal rendering Dec 9, 2025
Copilot AI requested a review from AdmGenSameer December 9, 2025 06:46
@AdmGenSameer AdmGenSameer marked this pull request as ready for review December 9, 2025 06:49
@AdmGenSameer AdmGenSameer merged commit 61bbd52 into main Dec 9, 2025
@AdmGenSameer AdmGenSameer deleted the copilot/fix-cli-bug-issues branch December 9, 2025 06:50
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.

2 participants