Class: Worktrees::Commands::List

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/worktrees/commands/list.rb

Instance Method Summary collapse

Instance Method Details

#call(**options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/worktrees/commands/list.rb', line 15

def call(**options)
  begin
    manager = WorktreeManager.new

    # Apply status filter
    status_filter = options[:filter] ? options[:filter].to_sym : nil
    worktrees = manager.list_worktrees(status: status_filter)

    if worktrees.empty?
      puts 'No worktrees found'
      return
    end

    case options[:format]
    when 'json'
      output_json(worktrees)
    when 'csv'
      output_csv(worktrees)
    else
      output_text(worktrees, options[:status_only])
    end

  rescue GitError => e
    warn "ERROR: Git: #{e.message}"
    exit(3)
  rescue StandardError => e
    warn "ERROR: #{e.message}"
    exit(1)
  end
end