Class: Transcriptic::CLI::Base

Inherits:
Thor
  • Object
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 # unfreeze frozen options Hash from Thor
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
      # transcriptic --help
      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



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/transcriptic/cli.rb', line 116

def analyze(object_path)
  raw = options.raw ? "--raw" : ""
  iterations = options.iterations ? options.iterations : 5
  require_labfile!
  update
  Transcriptic::SBT.stage
  data = `target/start #{object_path} --verify #{raw} --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

#compileObject



108
109
110
111
112
# File 'lib/transcriptic/cli.rb', line 108

def compile
  require_labfile!
  update
  Transcriptic::SBT.compile
end

#launch(object_path) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/transcriptic/cli.rb', line 153

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

#listObject



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

#loginObject



39
40
41
42
# File 'lib/transcriptic/cli.rb', line 39

def 
  Transcriptic::Auth.
  say "Authentication successful."
end

#logoutObject



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

#new(name) ⇒ Object



68
69
70
# File 'lib/transcriptic/cli.rb', line 68

def new(name)
  Transcriptic::ProjectGenerator.new([File.join(Dir.pwd, name), name], options).invoke_all
end

#publishObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/transcriptic/cli.rb', line 133

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

#tokenObject



51
52
53
# File 'lib/transcriptic/cli.rb', line 51

def token
  say Transcriptic::Auth.api_key
end

#updateObject



100
101
102
103
104
105
# File 'lib/transcriptic/cli.rb', line 100

def update
  require_labfile!
  output_with_arrow "Updating dependencies..."
  labfile = Transcriptic::Labfile.from_file(Transcriptic.find_labfile)
  Transcriptic::DependenciesGenerator.new([Dir.pwd, labfile.dependencies], options).invoke_all
end