Class: Git2Mite::Gui

Inherits:
Object
  • Object
show all
Defined in:
lib/git2mite/gui.rb

Instance Method Summary collapse

Instance Method Details

#ask(question) ⇒ Object



17
18
19
20
# File 'lib/git2mite/gui.rb', line 17

def ask(question)
  print "#{question}: "
  $stdin.gets
end

#error(reason) ⇒ Object



22
23
24
25
# File 'lib/git2mite/gui.rb', line 22

def error(reason)
  STDERR.puts reason
  exit(-1)
end

#get_author(authors) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/git2mite/gui.rb', line 45

def get_author(authors)
  puts "\n=== Git Authors ==="
  authors.each.with_index do |name, i|
    puts "#{i+1}\t#{name}"
  end
  choice = ask('Which author\'s commits to you want to use?')
  authors[choice.to_i - 1] || error('Invalid author')
end

#get_date(label) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/git2mite/gui.rb', line 54

def get_date(label)
  answer = ask("Enter the #{label} (yyyy-mm-dd) [#{Date.today}]")
  begin
    answer.strip.empty? ? Date.today : Date.parse(answer)
  rescue(ArgumentError)
    error('invalid date')
  end
end

#get_project_id(projects) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/git2mite/gui.rb', line 27

def get_project_id(projects)
  puts "=== Projects ==="
  projects.each.with_index do |project, i|
    puts "#{i+1}\t#{project['project']['name']}"
  end
  choice = ask('Which project do you want to write your commits to?')
  (projects[choice.to_i - 1] || error('invalid project id'))['project']['id']
end

#get_user_id(users) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/git2mite/gui.rb', line 36

def get_user_id(users)
  puts "\n=== Users ==="
  users.each.with_index do |user, i|
    puts "#{i+1}\t#{user.name}"
  end
  choice = ask('Which user do you want to write your commits to?')
  (users[choice.to_i - 1] || error('invalid user id')).id
end


3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/git2mite/gui.rb', line 3

def print_welcome
  puts "  Welcome to git2mite\n\n  This tool allows to you to write the commit log of\n  your git repository to your mite account in order\n  to auto-fill your timesheets.\n\n  Brought to you by http://upstre.am\n  Questions, Problems, Source Code: http://github.com/upstream/git2mite\n\n  WELCOME\nend\n"