Class: Ace::Git::Worktree::Commands::ListCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/worktree/commands/list_command.rb

Overview

List command

Lists worktrees with various formatting and filtering options. Supports task-aware listing and search capabilities.

Examples:

List all worktrees

ListCommand.new.run([])

List with JSON output

ListCommand.new.run(["--format", "json"])

List only task-associated worktrees

ListCommand.new.run(["--task-associated"])

Instance Method Summary collapse

Constructor Details

#initializeListCommand

Initialize a new ListCommand



22
23
24
# File 'lib/ace/git/worktree/commands/list_command.rb', line 22

def initialize
  @manager = Organisms::WorktreeManager.new
end

Instance Method Details

#run(args = []) ⇒ Integer

Run the list command

Parameters:

  • args (Array<String>) (defaults to: [])

    Command arguments

Returns:

  • (Integer)

    Exit code (0 for success, 1 for error)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ace/git/worktree/commands/list_command.rb', line 30

def run(args = [])
  options = parse_arguments(args)
  return show_help if options[:help]

  validate_options(options)

  # Convert format to symbol for WorktreeLister compatibility
  options[:format] = options[:format].to_sym if options[:format]

  result = @manager.list_all(options)

  if result[:success]
    display_list_result(result, options)
    0
  else
    puts "Failed to list worktrees: #{result[:error]}"
    1
  end
rescue ArgumentError => e
  puts "Error: #{e.message}"
  puts
  show_help
  1
rescue => e
  puts "Error: #{e.message}"
  1
end

#show_helpInteger

Show help for the list command

Returns:

  • (Integer)

    Exit code



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ace/git/worktree/commands/list_command.rb', line 61

def show_help
  puts <<~HELP
    ace-git-worktree list - List worktrees

    USAGE:
        ace-git-worktree list [OPTIONS]

    OUTPUT FORMATS:
        --format <format>       Output format: table, json, simple (default: table)
        --show-tasks            Include task associations

    FILTERING:
        --task-associated       Show only task-associated worktrees
        --no-task-associated    Show only non-task worktrees
        --usable               Show only usable worktrees
        --no-usable            Show only unusable worktrees
        --search <pattern>      Filter by branch name pattern

    EXAMPLES:
        # List all worktrees in table format
        ace-git-worktree list

        # List with task associations in JSON format
        ace-git-worktree list --show-tasks --format json

        # List only task-associated worktrees
        ace-git-worktree list --task-associated

        # Search for worktrees with "auth" in branch name
        ace-git-worktree list --search auth

        # List only usable worktrees
        ace-git-worktree list --usable

    OUTPUT:
        Table format columns:
        - Task: Task ID (or - for non-task worktrees)
        - Branch: Git branch name
        - Path: Worktree directory path
        - Status: worktree status (task, normal, bare, detached, etc.)

        JSON format includes full worktree details and metadata.
  HELP
  0
end