Class: Transcriptic::CLI::Base
- Inherits:
-
Thor
- Object
- Thor
- Transcriptic::CLI::Base
show all
- Includes:
- UI
- Defined in:
- lib/transcriptic/cli.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from UI
#arrow, #confirm, #confirm_billing, #confirm_command, #confirm_quote, #deprecate, disable_error_capture, #display, #display_row, #display_table, enable_error_capture, #error, #error_with_failure, extended, extended_into, #fail, #format_bytes, #format_date, #format_with_bang, #get_terminal_environment, included, included_into, #indent, #info, #json_decode, #json_encode, #longest, #mute!, #output, #output_with_arrow, #output_with_bang, #output_with_indent, #quantify, #quiet?, #redisplay, #say, #say_status, #set_buffer, #string_distance, #suggestion, #time_ago, #truncate, #unmute!, #wait_spinner, #warn
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/transcriptic/cli.rb', line 22
def initialize(*args)
super(*args)
Transcriptic.logger.level = ::Logger::INFO
if @options[:debug]
Transcriptic.logger.level = ::Logger::DEBUG
end
if @options[:quiet]
Transcriptic.ui.mute!
end
@options = options.dup end
|
Class Method Details
.dispatch(meth, given_args, given_opts, config) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/transcriptic/cli.rb', line 7
def dispatch(meth, given_args, given_opts, config)
unless (given_args & ['-h', '--help']).empty?
if given_args.length == 1
super
else
command = given_args.first
super(meth, ['help', command].compact, nil, config)
end
else
super
end
end
|
Instance Method Details
#analyze(object_path) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/transcriptic/cli.rb', line 136
def analyze(object_path)
raw = options.raw ? "--raw" : ""
linearize = options.linearize ? "--linearize" : ""
iterations = options.iterations ? options.iterations : 5
require_labfile!
update
Transcriptic::SBT.stage
data = `target/start #{object_path} --verify #{raw} #{linearize} --iterations #{iterations}`
if not options.raw
json = json_decode(data)
output_with_arrow "Verification successful for #{object_path}"
output_with_indent "Expected cost: $#{json["price_avg"]}, maximum observed cost: $#{json["price_max"]}"
else
say data
end
end
|
#compile ⇒ Object
128
129
130
131
132
|
# File 'lib/transcriptic/cli.rb', line 128
def compile
require_labfile!
update
Transcriptic::SBT.compile
end
|
#launch(object_path) ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/transcriptic/cli.rb', line 174
def launch(object_path)
require_labfile!
output_with_arrow "Not yet available!"
return
fd = create_protocol_fd_for_path(path)
if 1 == fd
Transcriptic.ui.error_with_failure "Couldn't packaged protocol filename or directory!"
end
if args.empty?
project_id = "default"
else
project_id = args.shift
end
run = action("Uploading `#{path}`") {
transcriptic.create_run(fd, project_id)
}
if run["success"]
Transcriptic.ui.output_with_arrow "Protocol received: #{run["protocol_format"]} detected"
Transcriptic.ui.output_with_arrow "Protocol received: #{run["nsteps"]} steps, expected cost: #{run["exp_cost"]}, total possible cost: #{run["max_cost"]}"
Transcriptic.ui.output_with_arrow "Protocol received: expected runtime: #{run["exp_time"]}, total possible runtime: #{run["max_time"]}"
if Transcriptic.ui.confirm_quote
Transcriptic.ui.display
Transcriptic.ui.action("Launching") {
transcriptic.launch_run(run["run_id"])
}
Transcriptic.ui.output_with_arrow "Protocol run launched. ID: #{run["run_id"]}"
Transcriptic.ui.output_with_arrow "Monitor at: https://secure.transcriptic.com/#{run["organization_id"]}/#{run["project_id"]}/runs/#{run["run_id"]}"
end
else
Transcriptic.ui.error_with_failure "Error creating protocol run."
end
end
|
#list ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/transcriptic/cli.rb', line 87
def list
ret = transcriptic.list
if ret.empty?
say "No runs for #{transcriptic.user}"
return
end
say("Runs:")
ret.each do |run|
say " #{run.name}"
end
end
|
#login ⇒ Object
39
40
41
42
|
# File 'lib/transcriptic/cli.rb', line 39
def login
Transcriptic::Auth.login
say "Authentication successful."
end
|
#logout ⇒ Object
45
46
47
48
|
# File 'lib/transcriptic/cli.rb', line 45
def logout
Transcriptic::Auth.logout
say "Local credentials cleared."
end
|
#logs(run_id) ⇒ Object
73
74
75
|
# File 'lib/transcriptic/cli.rb', line 73
def logs(run_id)
transcriptic.read_logs(run_id)
end
|
#lookup(term) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/transcriptic/cli.rb', line 111
def lookup(term)
ret = transcriptic.search_resources(term)
ret["results"].each do |result|
output_with_arrow "#{result[:resource_id]}: #{result[:name]}"
end
end
|
#publish ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/transcriptic/cli.rb', line 154
def publish
labfile = require_labfile!
if compile
dependencies = labfile.dependencies.map {|d| "#{d[:group]}.#{d[:name]}/#{d[:version]}" }.join(", ")
output_with_arrow "Preparing to publish..."
output_with_arrow "Project name: #{labfile.options[:name]}, Author: #{labfile.options[:author]}, Email: #{labfile.options[:email]}"
if labfile.options[:description]
output_with_arrow "Description: #{labfile.options[:description]}"
else
display format_with_bang("Warning: No description provided.")
end
if labfile.dependencies.length > 0
output_with_arrow "Dependencies: #{dependencies}}"
end
confirm(format_with_bang("Are you sure you want to publish version #{labfile.options[:version]} of this project? (y/N)"))
output_with_arrow "Not yet available!"
end
end
|
#status(run_id) ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/transcriptic/cli.rb', line 78
def status(run_id)
ret = transcriptic.status(run_id)
if ret.nil?
error "#{run_id} not found for #{transcriptic.user}"
end
say(ret.inspect)
end
|