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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bonchi/cli.rb', line 25 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 end end |
#init ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/bonchi/cli.rb', line 107 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
123 124 125 |
# File 'lib/bonchi/cli.rb', line 123 def list Git.worktree_list.each { |line| puts line } end |
#pr(input) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/bonchi/cli.rb', line 82 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
150 151 152 153 |
# File 'lib/bonchi/cli.rb', line 150 def prune Git.worktree_prune puts "Pruned stale worktree administrative files" end |
#remove(branch) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/bonchi/cli.rb', line 134 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 |
#setup(*args) ⇒ Object
118 119 120 |
# File 'lib/bonchi/cli.rb', line 118 def setup(*args) Setup.new.run(args) end |
#shellenv ⇒ Object
156 157 158 |
# File 'lib/bonchi/cli.rb', line 156 def shellenv puts SHELL_ENV end |
#switch(branch) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bonchi/cli.rb', line 55 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 |