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 validate]

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



60
61
62
# File 'lib/dip/cli.rb', line 60

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

#compose(*argv) ⇒ Object



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

def compose(*argv)
  require_relative "commands/preflight"
  require_relative "commands/compose"

  Dip::Commands::Preflight.new.execute
  Dip::Commands::Compose.new(*argv).execute
end

#down(*argv) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/dip/cli.rb', line 77

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



89
90
91
92
93
94
95
# File 'lib/dip/cli.rb', line 89

def ktl(*argv)
  require_relative "commands/preflight"
  require_relative "commands/kubectl"

  Dip::Commands::Preflight.new.execute
  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



119
120
121
122
123
124
125
126
# File 'lib/dip/cli.rb', line 119

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

#run(*argv) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/dip/cli.rb', line 101

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

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

#stop(*argv) ⇒ Object



70
71
72
# File 'lib/dip/cli.rb', line 70

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

#up(*argv) ⇒ Object



65
66
67
# File 'lib/dip/cli.rb', line 65

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

#validateObject



129
130
131
132
133
134
135
# File 'lib/dip/cli.rb', line 129

def validate
  Dip.config.validate
  puts "dip.yml is valid"
rescue Dip::Error => e
  warn "Validation failed: #{e.message}"
  exit 1
end

#versionObject



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

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