Class: GitLeft::CLI

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

Instance Method Summary collapse

Instance Method Details

#begin(opts = {}) ⇒ Object



6
7
8
9
10
11
12
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
39
40
41
42
43
44
45
46
47
48
# File 'lib/git_left/cli.rb', line 6

def begin(opts = {})
  puts "Before we begin, prune remote branches? (y/n)"
  if STDIN.getch == 'y'
    puts "Pruning remote branches..."
    `git remote prune origin`
  end

  puts "Okay, time to clean up your #{GitLeft::Branches.branches.count} local branches..."

  while(1) do
    begin
      @random_branch = GitLeft::Branches.random_branch

      if @random_branch.nil?
        puts "\nYou cleaned up all your branches!"
        break
      end

      @reporter = GitLeft::BranchReporter.new(@random_branch)
      @reporter.report

      case GitLeft::KeyParser.new(STDIN.getch).action
      when :delete
        GitLeft::Branches.delete(@random_branch)
        puts "#{@random_branch.name} deleted"
        next
      when :skip
        GitLeft::Branches.skip(@random_branch)
        puts "#{@random_branch.name} skipped"
        next
      when :quit
        puts "See ya!"
        break
      end
    rescue
      puts "A problem occurred performing that action. Skipping."
      GitLeft::Branches.skip(@random_branch)
    end
  end

  puts "\t#{GitLeft::Branches.skipped_branches.count} skipped"    
  puts "\t#{GitLeft::Branches.deleted_branches.count} deleted"
end

#yolo(opts = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/git_left/cli.rb', line 51

def yolo(opts = {})
  puts "Are you absolutely sure you want to delete your #{GitLeft::Branches.branches.count} local branches? (y/n)"

  if STDIN.getch == 'y'
    puts "I'm serious, this is not easily undone. Go through with it? (y/n)"

    if STDIN.getch == 'y'
      puts "Okay..."

      while branch = GitLeft::Branches.random_branch do
        GitLeft::Branches.delete(branch)
        puts "#{branch.name} deleted."
      end
    end
  end
end