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

#check_path?, #check_subpath?, #class_to_lowercase, class_to_lowercase, #delete_file, #ignore_path?, #ignore_path_base, #kwargs, #make_path, #path_checker, #search_file_upward

Constructor Details

#initializeBase

Returns a new instance of Base.



54
55
56
57
# File 'lib/dapp/cli/command/base.rb', line 54

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

Instance Method Details

#cli_options(**kwargs) ⇒ Object



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

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, dapp_command: run_method, **kwargs)
end

#log_dapp_running_time(dapp) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/dapp/cli/command/base.rb', line 81

def log_dapp_running_time(dapp)
  return yield unless log_running_time

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

#log_running_timeObject



92
93
94
# File 'lib/dapp/cli/command/base.rb', line 92

def log_running_time
  true
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: {}) ⇒ Object



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

def run_dapp_command(run_method, options: {})
  dapp = ::Dapp::Dapp.new(options: options)
  ::Dapp::CLI.dapp_object = dapp
  dapp.sentry_message("Manual usage: `#{options[:dapp_command]}` command") unless ENV['CI']

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

#run_methodObject



77
78
79
# File 'lib/dapp/cli/command/base.rb', line 77

def run_method
  class_to_lowercase
end