Class: EY::Pairing::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(argv) ⇒ Object



4
5
6
# File 'lib/ey_pairing/cli.rb', line 4

def self.run(argv)
  new.run(argv)
end

Instance Method Details

#choose_pairObject



22
23
24
25
26
# File 'lib/ey_pairing/cli.rb', line 22

def choose_pair
  choose_user("Pairing?") do |menu|
    menu.choice("np - Not Pairing") {nil}
  end
end

#choose_user(prompt = "Which user?") ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ey_pairing/cli.rb', line 28

def choose_user(prompt="Which user?")
  highline.choose do |menu|
    menu.prompt = prompt
    menu.index = :none
    menu.select_by = :name
    EY::Pairing::Author.all.each do |user|
      menu.choice("#{user.init} (#{user.name})") {user}
    end
    yield menu if block_given?
  end
end

#highlineObject



40
41
42
43
44
45
46
47
# File 'lib/ey_pairing/cli.rb', line 40

def highline
  @highline ||= begin
                  load_highline
                rescue LoadError
                  require 'rubygems'
                  load_highline
                end
end

#load_highlineObject



49
50
51
52
# File 'lib/ey_pairing/cli.rb', line 49

def load_highline
  require 'highline'
  HighLine.new(File.open('/dev/tty'))
end

#run(argv) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ey_pairing/cli.rb', line 8

def run(argv)
  puts "Welcome to ey-pairing v#{EY::Pairing::VERSION}"

  authors = [choose_user, choose_pair]
  names = authors.compact.map{|u| u.name }.join(" & ")
  email = authors.first.email

  `git config --remove-section user > /dev/null 2>&1` # remove project specific author
  `git config --global --replace-all user.name "#{names}"`
  `git config --global --replace-all user.email "#{email}"`

  puts %|~/.gitconfig author written: "#{names} <#{email}>"|
end