Class: Dapp::CLI::Command::Base

Inherits:
Dapp::CLI show all
Defined in:
lib/dapp/cli/command/base.rb

Constant Summary

Constants inherited from Dapp::CLI

SUBCOMMANDS

Instance Method Summary collapse

Methods included from Helper::Cli

#cli_wrapper, #composite_options, #in_validate!, #list_msg_format, #parse_options, #parse_subcommand, #prepare_subcommand, #required_argument, #run_subcommand

Methods included from Helper::Trivia

class_to_lowercase, #class_to_lowercase, #delete_file, #kwargs, #make_path, #search_file_upward

Constructor Details

#initializeBase

Returns a new instance of Base.



58
59
60
61
# File 'lib/dapp/cli/command/base.rb', line 58

def initialize
  self.class.options.merge!(Base.options)
  super()
end

Instance Method Details

#cli_options(**kwargs) ⇒ Object



90
91
92
# File 'lib/dapp/cli/command/base.rb', line 90

def cli_options(**kwargs)
  config.merge(**kwargs)
end

#log_dapp_running_time(dapp, ignore: false) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/dapp/cli/command/base.rb', line 75

def log_dapp_running_time(dapp, ignore: false)
  return yield if ignore

  begin
    start_time = Time.now
    yield
  ensure
    dapp.log_step("Running time #{(Time.now - start_time).round(2)} seconds")
  end
end

#run(_argv = ARGV) ⇒ Object



86
87
88
# File 'lib/dapp/cli/command/base.rb', line 86

def run(_argv = ARGV)
  raise
end

#run_dapp_command(run_method, options: {}, log_running_time: true) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dapp/cli/command/base.rb', line 63

def run_dapp_command(run_method, options: {}, log_running_time: true)
  dapp = ::Dapp::Dapp.new(options: options)

  log_dapp_running_time(dapp, ignore: !log_running_time) do
    if block_given?
      yield dapp
    elsif !run_method.nil?
      dapp.public_send(run_method)
    end
  end
end