Class: Bonchi::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/bonchi/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/bonchi/cli.rb', line 5

def self.exit_on_failure?
  true
end

Instance Method Details

#create(branch, base = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bonchi/cli.rb', line 18

def create(branch, base = nil)
  base ||= Git.default_base_branch
  path = Git.worktree_dir(branch)

  existing = Git.worktree_path_for(branch)
  if existing
    puts "Worktree already exists: #{existing}"
    puts "BONCHI_CD:#{existing}"
    return
  end

  Git.worktree_add_new_branch(path, branch, base)
  puts "Worktree created at: #{path}"

  if options[:setup] && Config.from_main_worktree
    puts ""
    Setup.new(worktree: path).run
  else
    puts "BONCHI_CD:#{path}"
  end
end

#listObject



86
87
88
# File 'lib/bonchi/cli.rb', line 86

def list
  Git.worktree_list.each { |line| puts line }
end

#pr(input) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bonchi/cli.rb', line 61

def pr(input)
  pr_number = extract_pr_number(input)
  branch = "pr-#{pr_number}"
  path = Git.worktree_dir(branch)

  existing = Git.worktree_path_for(branch)
  if existing
    puts "Worktree already exists: #{existing}"
    puts "BONCHI_CD:#{existing}"
    return
  end

  Git.fetch_pr(pr_number)
  Git.worktree_add(path, branch)
  puts "PR ##{pr_number} checked out at: #{path}"

  puts "BONCHI_CD:#{path}"
end

#pruneObject



100
101
102
103
# File 'lib/bonchi/cli.rb', line 100

def prune
  Git.worktree_prune
  puts "Pruned stale worktree administrative files"
end

#remove(branch) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/bonchi/cli.rb', line 91

def remove(branch)
  path = Git.worktree_path_for(branch)
  abort "Error: No worktree found for branch: #{branch}" unless path

  Git.worktree_remove(path)
  puts "Removed worktree: #{path}"
end

#setupObject



81
82
83
# File 'lib/bonchi/cli.rb', line 81

def setup
  Setup.new.run
end

#shellenvObject



106
107
108
# File 'lib/bonchi/cli.rb', line 106

def shellenv
  puts SHELL_ENV
end

#switch(branch) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bonchi/cli.rb', line 41

def switch(branch)
  existing = Git.worktree_path_for(branch)
  if existing
    puts "Worktree already exists: #{existing}"
    puts "BONCHI_CD:#{existing}"
    return
  end

  unless Git.branch_exists?(branch)
    abort "Error: Branch '#{branch}' does not exist\nUse 'bonchi create #{branch}' to create a new branch"
  end

  path = Git.worktree_dir(branch)
  Git.worktree_add(path, branch)
  puts "Worktree created at: #{path}"

  puts "BONCHI_CD:#{path}"
end

#versionObject



10
11
12
# File 'lib/bonchi/cli.rb', line 10

def version
  puts "bonchi #{VERSION}"
end