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, #print_error_with_help_and_die!, #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.



62
63
64
65
# File 'lib/dapp/cli/command/base.rb', line 62

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

Instance Method Details

#before_dapp_run_command(dapp, &blk) ⇒ Object



100
101
102
103
# File 'lib/dapp/cli/command/base.rb', line 100

def before_dapp_run_command(dapp, &blk)
  yield if block_given?
  dapp.
end

#cli_options(**kwargs) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/dapp/cli/command/base.rb', line 105

def cli_options(**kwargs)
  dirs = [config[:build_dir], config[:run_dir], config[:deploy_dir]]
  if dirs.compact.size > 1
    self.class.print_error_with_help_and_die! self, "cannot use alias options --run-dir, --build-dir, --deploy-dir at the same time"
  end

  config.merge(build_dir: dirs.compact.first, **kwargs)
end

#log_dapp_running_time(dapp, ignore: false) ⇒ Object



85
86
87
88
89
90
91
92
93
94
# File 'lib/dapp/cli/command/base.rb', line 85

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



96
97
98
# File 'lib/dapp/cli/command/base.rb', line 96

def run(_argv = ARGV)
  raise
end

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



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dapp/cli/command/base.rb', line 67

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
    begin
      before_dapp_run_command(dapp)

      if block_given?
        yield dapp
      elsif !run_method.nil?
        dapp.public_send(run_method)
      end
    ensure
      dapp.terminate
    end
  end
end