Class: TicGit::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, *args) ⇒ CLI

Returns a new instance of CLI.



8
9
10
11
12
13
14
# File 'lib/ticgit/cli.rb', line 8

def initialize(opts = {}, *args)
  @tic = TicGit.open('.', :keep_state => true)
  $stdout.sync = true # so that Net::SSH prompts show up
rescue NoRepoFound
  puts "No repo found"
  exit
end

Instance Attribute Details

#ticObject (readonly)

Returns the value of attribute tic.



6
7
8
# File 'lib/ticgit/cli.rb', line 6

def tic
  @tic
end

Instance Method Details

#assign(ticket_id = nil) ⇒ Object



98
99
100
101
# File 'lib/ticgit/cli.rb', line 98

def assign(ticket_id = nil)
  tic.ticket_checkout(options[:checkout]) if options[:checkout]
  tic.ticket_assign(options[:user], ticket_id)
end

#checkout(ticket_id) ⇒ Object



69
70
71
# File 'lib/ticgit/cli.rb', line 69

def checkout(ticket_id)
  tic.ticket_checkout(ticket_id)
end

#comment(ticket_id = nil) ⇒ Object



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

def comment(ticket_id = nil)
  if options[:file]
    raise ArgumentError, "Only 1 of -f/--file and -m/--message can be specified" if options[:message]
    file = options[:file]
    raise ArgumentError, "File #{file} doesn't exist" unless File.file?(file)
    raise ArgumentError, "File #{file} must be <= 2048 bytes" unless File.size(file) <= 2048
    tic.ticket_comment(File.read(file), ticket_id)
  elsif m = options[:message]
    tic.ticket_comment(m, ticket_id)
  else
    message, meta = get_editor_message
    if message
      tic.ticket_comment(message.join(''), ticket_id)
    end
  end
end

#list(saved_query = nil) ⇒ Object



113
114
115
116
117
118
119
120
# File 'lib/ticgit/cli.rb', line 113

def list(saved_query = nil)
  opts = options.dup
  opts[:saved] = saved_query if saved_query
  
  if tickets = tic.ticket_list(opts)
    output_ticket_list(tickets)
  end
end

#milestone(name = nil) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/ticgit/cli.rb', line 23

def milestone(name = nil)
  raise NotImplementedError
end

#newObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ticgit/cli.rb', line 133

def new
  if title = options[:title]
    ticket_show(@tic.ticket_new(title, options))
  else
    # interactive
    message_file = Tempfile.new('ticgit_message').path
    File.open(message_file, 'w') do |f|
      f.puts "\n# ---"
      f.puts "tags:"
      f.puts "# The first line will be the title of the ticket,"
      f.puts "# the rest will be the description. If you would like to add initial tags,"
      f.puts "# put them on the 'tags:' line, comma delimited"
    end
    
    message, meta = get_editor_message(message_file)
    if message
      title, description, tags = parse_editor_message(message,meta)
      if title and !title.empty?
        ticket_show(@tic.ticket_new(title, :description => description, :tags => tags))
      else
        puts "You need to at least enter a title"
      end
    else
      puts "It seems you wrote nothing"
    end
  end
end

#recent(ticket_id = nil) ⇒ Object



28
29
30
31
32
# File 'lib/ticgit/cli.rb', line 28

def recent(ticket_id = nil)
  tic.ticket_recent(ticket_id).each do |commit|
    puts commit.sha[0, 7] + "  " + commit.date.strftime("%m/%d %H:%M") + "\t" + commit.message
  end
end

#show(ticket_id = nil) ⇒ Object



125
126
127
128
129
# File 'lib/ticgit/cli.rb', line 125

def show(ticket_id = nil)
  if t = @tic.ticket_show(ticket_id)
    ticket_show(t)
  end
end

#state(id_or_state, state = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ticgit/cli.rb', line 74

def state(id_or_state, state = nil)
  if state.nil?
    state = id_or_state
    ticket_id = nil
  else
    ticket_id = id_or_state
  end
  
  if valid_state(state)
    tic.ticket_change(state, ticket_id)
  else
    puts 'Invalid State - please choose from : ' + tic.tic_states.join(", ")
  end
end

#tag(*args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ticgit/cli.rb', line 36

def tag(*args)
  puts 'remove' if options[:remove]
  
  tid = args.size > 1 && args.shift
  tags = args.first
  
  if tags
    tic.ticket_tag(tags, tid, options)
  else  
    puts 'You need to at least specify one tag to add'
  end
end