Class: Worktrees::Commands::Status

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

Instance Method Summary collapse

Instance Method Details

#call(**options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/worktrees/commands/status.rb', line 13

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

    if current_worktree.nil?
      warn 'ERROR: Not in a worktree'
      show_repository_info(manager, options[:format])
      exit(4)
    end

    case options[:format]
    when 'json'
      output_json(current_worktree, manager)
    else
      output_text(current_worktree, manager)
    end

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