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



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

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, ignore: false) ⇒ Object



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

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



94
95
96
# File 'lib/dapp/cli/command/base.rb', line 94

def run(_argv = ARGV)
  raise
end

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



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

def run_dapp_command(run_method, options: {}, log_running_time: true, try_host_docker_login: false)
  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, ignore: !log_running_time) do
    begin
      dapp. if 

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

#run_methodObject



79
80
81
# File 'lib/dapp/cli/command/base.rb', line 79

def run_method
  class_to_lowercase
end