class Tumugi::CLI

Public Class Methods

common_options() click to toggle source
# File lib/tumugi/cli.rb, line 10
def common_options
  option :file, aliases: '-f', desc: 'Workflow file name', required: true
  option :config, aliases: '-c', desc: 'Configuration file name'
  option :params, aliases: '-p', type: :hash, desc: 'Task parameters'
  option :quiet, type: :boolean, desc: 'Suppress log', default: false
  option :verbose, type: :boolean, desc: 'Show verbose log', default: false
  option :log_format, type: :string, desc: 'Log format', enum: ['text', 'json'], default: 'text'
end
exit_on_failure?() click to toggle source
# File lib/tumugi/cli.rb, line 19
def exit_on_failure?
  true
end

Public Instance Methods

init(path='') click to toggle source
# File lib/tumugi/cli.rb, line 55
def init(path='')
  generate_project('project', path, force: true)
end
new(type, name) click to toggle source
# File lib/tumugi/cli.rb, line 50
def new(type, name)
  generate_project(type, name, options)
end
run_(task) click to toggle source
# File lib/tumugi/cli.rb, line 35
def run_(task)
  execute(:run, task, options)
end
show(task) click to toggle source
# File lib/tumugi/cli.rb, line 43
def show(task)
  opts = options.dup
  opts[:quiet] = true if opts[:out].nil?
  execute(:show, task, opts.freeze)
end
version() click to toggle source
# File lib/tumugi/cli.rb, line 25
def version
  puts "tumugi v#{Tumugi::VERSION}"
end

Private Instance Methods

execute(command, task, options) click to toggle source
# File lib/tumugi/cli.rb, line 61
def execute(command, task, options)
  logger.info "tumugi v#{Tumugi::VERSION}"
  args = { task: task, options: options }
  logger.info "status: running, command: #{command}, args: #{args}"
  success = Tumugi.workflow.execute(command, task, options)
  unless success
    raise Thor::Error, "execute finished, but failed"
  end
  logger.info "status: success, command: #{command}, args: #{args}"
rescue => e
  handle_error(command, e, args)
end
generate_project(type, name, options) click to toggle source
# File lib/tumugi/cli.rb, line 74
def generate_project(type, name, options)
  logger.info "tumugi v#{Tumugi::VERSION}"
  args = { type: type, name: name, options: options }
  logger.info "status: running, command: new, args: #{args}"
  Tumugi::Command::New.new.execute(type, name, options)
  logger.info "status: success, command: new, args: #{args}"
rescue => e
  handle_error("new", e, args)
end
handle_error(command, e, args) click to toggle source
# File lib/tumugi/cli.rb, line 86
def handle_error(command, e, args)
  logger.error "#{command} command failed"
  logger.error e.message
  reason = e
  if e.is_a?(Tumugi::TumugiError) && !e.reason.nil?
    reason = e.reason
    logger.error reason.message
  end
  if options[:verbose]
    logger.error { reason.backtrace.join("\n") }
  else
    logger.error "If you want to know more detail, run with '--verbose' option"
  end
  logger.error "status: failed, command: #{command}, args: #{args}"
  raise Thor::Error.new("tumugi #{command} failed, please check log")
end
logger() click to toggle source
# File lib/tumugi/cli.rb, line 103
def logger
  @logger ||= Tumugi::ScopedLogger.new("tumugi-main")
end