class Transcriptic::CLI::Base

Public Class Methods

dispatch(meth, given_args, given_opts, config) click to toggle source
Calls superclass method
# 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
new(*args) click to toggle source
Calls superclass method
# 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

Public Instance Methods

analyze(object_path, *params) click to toggle source
# File lib/transcriptic/cli.rb, line 142
def analyze(object_path, *params)
  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} #{params.join(" ")}`
  if not options.raw
    File.open("logs/#{object_path}", 'w') { |file| file.write(data) }
    data = data.split("\n")[-1]
    json = json_decode(data)
    output_with_arrow "Verification successful for #{object_path}"
    output_with_arrow "Logged output during verification to logs/#{object_path}"
    output_with_indent "Expected cost: $#{json["price_avg"]}, maximum observed cost: $#{json["price_max"]}"
  else
    say data
  end
end
clean() click to toggle source
# File lib/transcriptic/cli.rb, line 134
def clean
  require_labfile!
  update
  Transcriptic::SBT.compile
end
compile() click to toggle source
# File lib/transcriptic/cli.rb, line 127
def compile
  require_labfile!
  update
  Transcriptic::SBT.compile
end
launch(object_path) click to toggle source
# File lib/transcriptic/cli.rb, line 199
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_client.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_client.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_client.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() click to toggle source
# File lib/transcriptic/cli.rb, line 87
def list
  ret = transcriptic_client.list_runs
  if ret.empty?
    say "No runs for #{transcriptic_client.user}"
    return
  end
  ret.each do |run|
    say "#{run["title"]}\t#{run["id"]}\t#{run["partials"].length} partials\t#{run["status"]}"
  end
end
login() click to toggle source
# File lib/transcriptic/cli.rb, line 39
def login
  Transcriptic::Auth.login
  say "Authentication successful."
end
logout() click to toggle source
# File lib/transcriptic/cli.rb, line 45
def logout
  Transcriptic::Auth.logout
  say "Local credentials cleared."
end
logs(run_id) click to toggle source
# File lib/transcriptic/cli.rb, line 73
def logs(run_id)
  transcriptic_client.read_logs(run_id)
end
lookup(term) click to toggle source
# File lib/transcriptic/cli.rb, line 110
def lookup(term)
  ret = transcriptic_client.search_resources(term)
  ret["results"].each do |result|
    output_with_arrow "#{result[:resource_id]}: #{result[:name]}"
  end
end
new(name) click to toggle source
# File lib/transcriptic/cli.rb, line 68
def new(name)
  Transcriptic::ProjectGenerator.new([File.join(Dir.pwd, name), name], options).generate
end
publish() click to toggle source
# File lib/transcriptic/cli.rb, line 163
def publish
  labfile = require_labfile!
  update
  Transcriptic::SBT.clean
  compiled_jar_path = Transcriptic::SBT.stage
  if compiled_jar_path
    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
    if confirm(format_with_bang("Are you sure you want to publish version #{labfile.options[:version]} of this project? (y/N)"))
      output_with_arrow "Uploading #{compiled_jar_path} to Transcriptic..."

      signature = transcriptic_client.sign_upload(labfile, File.basename(compiled_jar_path))
      res = transcriptic_client.create_or_get_protocol(labfile, signature)
      if res["success"]
        transcriptic_client.upload_to_s3(compiled_jar_path, signature)
        output_with_arrow "Revision #{labfile.options[:version]} of #{labfile.options[:name]} published!"
      else
        errors = res["errors"].map { |e| e[1].map { |m| "#{e[0]} #{m}" }.join(", ") }.join(", ")
        display format_with_bang("Errors occurred: #{errors}")
      end
    else
      display "Aborting."
    end
  end
end
status(run_id) click to toggle source
# File lib/transcriptic/cli.rb, line 78
def status(run_id)
  ret = transcriptic_client.run_info(run_id)
  if ret.nil?
    error "#{run_id} not found for #{transcriptic_client.user}"
  end
  say ret["status"]
end
token() click to toggle source
# File lib/transcriptic/cli.rb, line 51
def token
  say Transcriptic::Auth.api_key
end
update() click to toggle source
# File lib/transcriptic/cli.rb, line 118
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
  Transcriptic::ProjectGenerator.new([Dir.pwd, labfile.options[:name]], options).update_build_version(labfile)
end

Private Instance Methods

require_labfile!() click to toggle source
# File lib/transcriptic/cli.rb, line 239
def require_labfile!
  labfile = Transcriptic.find_labfile
  if labfile.nil?
    error("Can't find Labfile!  You must run this command from within an autoprotocol project directory.")
  end
  Transcriptic::Labfile.from_file(labfile)
end
transcriptic_client() click to toggle source
# File lib/transcriptic/cli.rb, line 235
def transcriptic_client
  Transcriptic::Auth.client
end