Class: Bonchi::CLI
- Inherits:
-
Thor
- Object
- Thor
- Bonchi::CLI
- Defined in:
- lib/bonchi/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create(branch, base = nil) ⇒ Object
- #init ⇒ Object
- #list ⇒ Object
- #pr(input) ⇒ Object
- #prune ⇒ Object
- #remove(branch) ⇒ Object
- #setup(*args) ⇒ Object
- #shellenv ⇒ Object
- #switch(branch) ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ 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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bonchi/cli.rb', line 27 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}" signal_cd(existing) return end Git.worktree_add_new_branch(path, branch, base) puts "Worktree created at: #{path}" signal_cd(path) if [:setup] && Config.from_main_worktree puts "" Setup.new(worktree: path).run(upto: [:upto]) end end |
#init ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/bonchi/cli.rb', line 109 def init path = File.join(Dir.pwd, ".worktree.yml") if File.exist?(path) abort "Error: .worktree.yml already exists" end File.write(path, WORKTREE_YML_TEMPLATE) puts "Created #{path}" end |
#list ⇒ Object
126 127 128 |
# File 'lib/bonchi/cli.rb', line 126 def list Git.worktree_list.each { |line| puts line } end |
#pr(input) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/bonchi/cli.rb', line 84 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}" signal_cd(existing) return end Git.fetch_pr(pr_number) Git.worktree_add(path, branch) puts "PR ##{pr_number} checked out at: #{path}" signal_cd(path) end |
#prune ⇒ Object
155 156 157 158 |
# File 'lib/bonchi/cli.rb', line 155 def prune Git.worktree_prune puts "Pruned stale worktree administrative files" end |
#remove(branch) ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/bonchi/cli.rb', line 138 def remove(branch) path = Git.worktree_path_for(branch) abort "Error: No worktree found for branch: #{branch}" unless path Git.worktree_remove(path, force: [:force]) puts "Removed worktree: #{path}" signal_cd(Git.main_worktree) end |
#setup(*args) ⇒ Object
121 122 123 |
# File 'lib/bonchi/cli.rb', line 121 def setup(*args) Setup.new.run(args, upto: [:upto]) end |
#shellenv ⇒ Object
161 162 163 |
# File 'lib/bonchi/cli.rb', line 161 def shellenv puts SHELL_ENV end |
#switch(branch) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bonchi/cli.rb', line 57 def switch(branch) existing = Git.worktree_path_for(branch) if existing puts "Worktree already exists: #{existing}" signal_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}" signal_cd(path) end |
#version ⇒ Object
10 11 12 |
# File 'lib/bonchi/cli.rb', line 10 def version puts "bonchi #{VERSION}" end |