ipt 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,184 @@
1
+ require 'highline'
2
+ module PT
3
+ module IO
4
+
5
+ ACTION = %w[show open start finish deliver accept reject done assign estimate tasks comment label ]
6
+ # I/O
7
+
8
+ def split_lines(text)
9
+ text.respond_to?(:join) ? text.join("\n") : text
10
+ end
11
+
12
+ def title(*msg)
13
+ puts "\n#{split_lines(msg)}".bold
14
+ end
15
+
16
+ def congrats(*msg)
17
+ puts "\n#{split_lines(msg).green.bold}"
18
+ end
19
+
20
+ def message(*msg)
21
+ puts "\n#{split_lines(msg)}"
22
+ end
23
+
24
+ def compact_message(*msg)
25
+ puts "#{split_lines(msg)}"
26
+ end
27
+
28
+ def error(*msg)
29
+ puts "\n#{split_lines(msg).red.bold}"
30
+ end
31
+
32
+ def quit
33
+ message "bye!"
34
+ exit
35
+ end
36
+
37
+ def ask(msg)
38
+ HighLine.new.ask(msg)
39
+ end
40
+
41
+ def ask_secret(msg)
42
+ HighLine.new.ask("#{msg.bold}"){ |q| q.echo = '*' }
43
+ end
44
+
45
+ def user_s
46
+ "#{Settings[:user_name]} (#{Settings[:user_initials]})"
47
+ end
48
+
49
+ def project_to_s
50
+ "Project #{Settings[:project_name].upcase}"
51
+ end
52
+
53
+ def get_open_story_task_from_params(task)
54
+ title "Pending tasks for '#{task.name}'"
55
+ task_struct = Struct.new(:description, :position)
56
+
57
+ pending_tasks = [
58
+ task_struct.new('<< Add new task >>', -1)
59
+ ]
60
+
61
+ task.tasks.each{ |t| pending_tasks << t unless t.complete }
62
+ table = TodoTaskTable.new(pending_tasks)
63
+ select("Pick task to edit, 1 to add new task", table)
64
+ end
65
+
66
+ def clear
67
+ puts "\e[H\e[2J"
68
+ end
69
+
70
+ def select(msg, table)
71
+ if table.length > 0
72
+ begin
73
+ table.print
74
+ row = ask "#{msg} (1-#{table.length}, 'q' to exit)".magenta
75
+ if row == 'q'
76
+ quit
77
+ elsif row.to_i > 0
78
+ selected = table[row]
79
+ error "Invalid selection, try again:" unless selected
80
+ elsif %w[n p q c r f].include?(row)
81
+ return row
82
+ end
83
+ end until selected
84
+ selected
85
+ else
86
+ table.print
87
+ error "Sorry, there are no options to select."
88
+ return 'EOF'
89
+ end
90
+ end
91
+
92
+ def select_story_from_paginated_table(options={}, &block)
93
+ prompt = "Please select a story"
94
+ page = 0
95
+ no_request = false
96
+ begin
97
+ say('Please wait...')
98
+ stories = block.call(page) unless no_request
99
+ current_page = @client.current_page
100
+ total_page = @client.total_page
101
+ title = (options[:title] || 'Stories').to_s + " [#{current_page}/#{total_page}]"
102
+ table = TasksTable.new(stories, title)
103
+ clear
104
+ say "Pivotal Tracker Command Line v#{PT::VERSION}".magenta
105
+ say '========================================================================================='.green
106
+ help = "[num]: select | [f]ilter | #{'[n]ext |' if current_page < total_page} #{'[p]revious |' if current_page > 1} [c]reate | [r]efresh | [q]uit"
107
+ say help.green
108
+ say '========================================================================================='.green
109
+ case story = select(prompt, table)
110
+ when TrackerApi::Resources::Story
111
+ say "Action for >> '#{story.name.green}'[#{story.story_type}]"
112
+ action = (options[:default_action] ? send("#{options[:default_action]}_story", story) : choose_action(story))
113
+ no_request = action == :no_request
114
+ when String
115
+ if story == 'n'
116
+ old_page = page
117
+ page+=1
118
+ elsif story == 'p'
119
+ old_page = page
120
+ page-=1
121
+ elsif story == 'q'
122
+ quit
123
+ elsif story == 'c'
124
+ create_interactive_story
125
+ elsif story == 'f'
126
+ choose_filter
127
+ elsif story == 'EOF'
128
+ HighLine.new.choose do |menu|
129
+ menu.prompt = "Please choose action ( [number/name]:select action)".magenta
130
+ menu.choice(:filter) { choose_filter }
131
+ menu.choice(:back) { say('back to table ....'); page-=1 }
132
+ menu.choice(:quit) { quit }
133
+ menu.default = :quit
134
+ end
135
+ elsif story == 'r'
136
+ page = old_page
137
+ end
138
+ no_request = false
139
+ else
140
+ error "Invalid selection, try again:"
141
+ no_request = true
142
+ end
143
+ end while true
144
+ end
145
+
146
+ def choose_action(story)
147
+ HighLine.new.choose do |menu|
148
+ menu.prompt = "Please choose action ( [number/name]:select action | [Enter]:show story )".magenta
149
+ menu.choice(:view, 'view details of story','view') { show_story(story) }
150
+ menu.choice(:edit, nil,'edit story') { edit_story(story) }
151
+ menu.choice(:start, nil,'start'.white) { start_story(story) }
152
+ menu.choice(:finish, nil,'finish'.blue) { finish_story(story) }
153
+ menu.choice(:deliver, nil,'deliver'.yellow) { deliver_story(story) }
154
+ menu.choice(:accept, nil,'accept'.green) { accept_story(story) }
155
+ menu.choice(:reject, nil,'reject'.red) { reject_story(story) }
156
+ %w[unstart assign estimate tasks comment label open].each do |action|
157
+ menu.choice(action.to_sym) { send("#{action}_story", story) }
158
+ end
159
+ menu.choice('id (copy story id)') { copy_story_id(story)}
160
+ menu.choice('url (copy story url)') { copy_story_url(story) }
161
+ menu.choice(:back) { say('back to table ....'); return :no_request }
162
+ menu.choice(:quit) { quit }
163
+ menu.default = :view
164
+ end
165
+ end
166
+
167
+ def choose_filter
168
+ HighLine.new.choose do |menu|
169
+ menu.prompt = "Please choose filter ( [number/name]:select filter | [Enter]:back to table)".magenta
170
+ %w[current backlog mywork bug feature unstarted started finished delivered accepted rejected].each do |f|
171
+ menu.choice(f.to_sym) do
172
+ say 'filtering ' + f
173
+ send(f.to_sym)
174
+ end
175
+ end
176
+ menu.choice(:search) { find }
177
+ menu.choice(:cancel) { say('back to table ....'); return :no_request }
178
+ menu.choice(:quit) { quit }
179
+ menu.default = :back
180
+ end
181
+ end
182
+ end
183
+ end
184
+
@@ -0,0 +1,3 @@
1
+ module PT
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,235 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ipt
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Slamet Kristanto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aruba
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: highline
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.0.0.pre.develop.6
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.0.0.pre.develop.6
111
+ - !ruby/object:Gem::Dependency
112
+ name: tracker_api
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.6.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.6.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: thor
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: terminal-table
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: paint
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: config
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Interactive Pivotal Tracker Command Line Interface
182
+ email:
183
+ - cakmet14@gmail.com
184
+ executables:
185
+ - ipt
186
+ extensions: []
187
+ extra_rdoc_files: []
188
+ files:
189
+ - ".gitignore"
190
+ - ".travis.yml"
191
+ - CODE_OF_CONDUCT.md
192
+ - Changelog.md
193
+ - Gemfile
194
+ - Guardfile
195
+ - LICENSE.txt
196
+ - README.md
197
+ - Rakefile
198
+ - bin/console
199
+ - bin/ipt
200
+ - bin/setup
201
+ - ipt.gemspec
202
+ - lib/pt.rb
203
+ - lib/pt/action.rb
204
+ - lib/pt/cli.rb
205
+ - lib/pt/client.rb
206
+ - lib/pt/configuration.rb
207
+ - lib/pt/data_row.rb
208
+ - lib/pt/data_table.rb
209
+ - lib/pt/io.rb
210
+ - lib/pt/version.rb
211
+ homepage: http://www.github.com/drselump14/ipt
212
+ licenses:
213
+ - MIT
214
+ metadata: {}
215
+ post_install_message:
216
+ rdoc_options: []
217
+ require_paths:
218
+ - lib
219
+ required_ruby_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ requirements: []
230
+ rubyforge_project:
231
+ rubygems_version: 2.6.8
232
+ signing_key:
233
+ specification_version: 4
234
+ summary: Interactive Pivotal Tracker CLI (API v5)
235
+ test_files: []