Class: TicGit::CLI
- Inherits:
-
Thor
- Object
- Thor
- TicGit::CLI
- Defined in:
- lib/ticgit/cli.rb
Instance Attribute Summary collapse
-
#tic ⇒ Object
readonly
Returns the value of attribute tic.
Instance Method Summary collapse
- #assign(ticket_id = nil) ⇒ Object
- #checkout(ticket_id) ⇒ Object
- #comment(ticket_id = nil) ⇒ Object
-
#initialize(opts = {}, *args) ⇒ CLI
constructor
A new instance of CLI.
- #list(saved_query = nil) ⇒ Object
- #milestone(name = nil) ⇒ Object
- #new ⇒ Object
- #recent(ticket_id = nil) ⇒ Object
- #show(ticket_id = nil) ⇒ Object
- #state(id_or_state, state = nil) ⇒ Object
- #tag(*args) ⇒ Object
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
#tic ⇒ Object (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([:checkout]) if [:checkout] tic.ticket_assign([: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 [:file] raise ArgumentError, "Only 1 of -f/--file and -m/--message can be specified" if [:message] file = [: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 = [:message] tic.ticket_comment(m, ticket_id) else , = if tic.ticket_comment(.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 = .dup opts[:saved] = saved_query if saved_query if tickets = tic.ticket_list(opts) output_ticket_list(tickets) end end |
#milestone(name = nil) ⇒ Object
23 24 25 |
# File 'lib/ticgit/cli.rb', line 23 def milestone(name = nil) raise NotImplementedError end |
#new ⇒ Object
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 = [:title] ticket_show(@tic.ticket_new(title, )) else # interactive = Tempfile.new('ticgit_message').path File.open(, '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 , = () if title, description, = (,) if title and !title.empty? ticket_show(@tic.ticket_new(title, :description => description, :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. 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 [:remove] tid = args.size > 1 && args.shift = args.first if tic.ticket_tag(, tid, ) else puts 'You need to at least specify one tag to add' end end |