Class: Dip::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/dip/cli.rb,
lib/dip/cli/dns.rb,
lib/dip/cli/ssh.rb,
lib/dip/cli/base.rb,
lib/dip/cli/infra.rb,
lib/dip/cli/console.rb

Defined Under Namespace

Classes: Base, Console, DNS, Infra, SSH

Constant Summary collapse

TOP_LEVEL_COMMANDS =
%w[help version ls compose up stop down run provision ssh infra console].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/dip/cli.rb', line 18

def exit_on_failure?
  true
end

.is_thor_reserved_word?(word, type) ⇒ Boolean

Hackery. Take the run method away from Thor so that we can redefine it.

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/dip/cli.rb', line 12

def is_thor_reserved_word?(word, type)
  return false if word == "run"

  super
end

.start(argv) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dip/cli.rb', line 22

def start(argv)
  argv = Dip::RunVars.call(argv, ENV)

  cmd = argv.first

  if cmd && !TOP_LEVEL_COMMANDS.include?(cmd) && Dip.config.exist? && Dip.config.interaction.key?(cmd.to_sym)
    argv.unshift("run")
  end

  super(Dip::RunVars.call(argv, ENV))
end

Instance Method Details

#build(*argv) ⇒ Object



57
58
59
# File 'lib/dip/cli.rb', line 57

def build(*argv)
  compose("build", *argv)
end

#compose(*argv) ⇒ Object



51
52
53
54
# File 'lib/dip/cli.rb', line 51

def compose(*argv)
  require_relative "commands/compose"
  Dip::Commands::Compose.new(*argv).execute
end

#down(*argv) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/dip/cli.rb', line 74

def down(*argv)
  if options[:help]
    invoke :help, ["down"]
  elsif options[:all]
    require_relative "commands/down_all"
    Dip::Commands::DownAll.new.execute
  else
    compose("down", *argv.push("--remove-orphans"))
  end
end

#ktl(*argv) ⇒ Object



86
87
88
89
# File 'lib/dip/cli.rb', line 86

def ktl(*argv)
  require_relative "commands/kubectl"
  Dip::Commands::Kubectl.new(*argv).execute
end

#lsObject



45
46
47
48
# File 'lib/dip/cli.rb', line 45

def ls
  require_relative "commands/list"
  Dip::Commands::List.new.execute
end

#provisionObject



111
112
113
114
115
116
117
118
# File 'lib/dip/cli.rb', line 111

def provision
  if options[:help]
    invoke :help, ["provision"]
  else
    require_relative "commands/provision"
    Dip::Commands::Provision.new.execute
  end
end

#run(*argv) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/dip/cli.rb', line 95

def run(*argv)
  if argv.empty? || options[:help]
    invoke :help, ["run"]
  else
    require_relative "commands/run"

    Dip::Commands::Run.new(
      *argv,
      **options.to_h.transform_keys!(&:to_sym)
    ).execute
  end
end

#stop(*argv) ⇒ Object



67
68
69
# File 'lib/dip/cli.rb', line 67

def stop(*argv)
  compose("stop", *argv)
end

#up(*argv) ⇒ Object



62
63
64
# File 'lib/dip/cli.rb', line 62

def up(*argv)
  compose("up", *argv)
end

#versionObject



38
39
40
41
# File 'lib/dip/cli.rb', line 38

def version
  require_relative "version"
  puts Dip::VERSION
end