Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Moved the CLI options to their own module and pass them into execute …
Browse files Browse the repository at this point in the history
…instead of setting an instance variable
  • Loading branch information
Metallion committed Oct 10, 2019
1 parent 62175ac commit fa7efb4
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 30 deletions.
1 change: 1 addition & 0 deletions lib/kaiser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'kaiser/version'
require 'kaiser/kaiserfile'
require 'kaiser/cli_options'
require 'kaiser/cli'
require 'kaiser/after_dotter'
require 'kaiser/dotter'
Expand Down
19 changes: 3 additions & 16 deletions lib/kaiser/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,7 @@
module Kaiser
# The commandline
class Cli
@options = []

class << self
def option(*option)
@options ||= []
@options << option
end

def options
@options || []
end
end

attr_reader :opts
extend Kaiser::CliOptions

def set_config
# This is here for backwards compatibility since it can be used in Kaiserfiles.
Expand All @@ -44,7 +31,7 @@ def define_options(global_opts = [])
# the scope to Optimist::Parser. We can still reference variables but we can't
# call instance methods of a Kaiser::Cli class.
u = usage
@opts = Optimist.options do
Optimist.options do
banner u

global_opts.each { |o| opt *o }
Expand Down Expand Up @@ -86,7 +73,7 @@ def self.run_command(name, global_opts)
)
cmd.set_config

cmd.execute
cmd.execute(opts)
end

def self.all_subcommands_usage
Expand Down
14 changes: 14 additions & 0 deletions lib/kaiser/cli_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Kaiser
module CliOptions
def option(*option)
@options ||= []
@options << option
end

def options
@options || []
end
end
end
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/attach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def usage
EOS
end

def execute
def execute(opts)
ensure_setup
attach_app
start_app
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/db_load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def usage
EOS
end

def execute
def execute(opts)
ensure_setup
name = ARGV.shift || '.default'
load_db(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/db_reset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def usage
EOS
end

def execute
def execute(opts)
ensure_setup
load_db('.default')
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/db_reset_hard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def usage
EOS
end

def execute
def execute(opts)
ensure_setup
FileUtils.rm db_image_path('.default') if File.exist?(db_image_path('.default'))
setup_db
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/db_save.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def usage
EOS
end

def execute
def execute(opts)
ensure_setup
name = ARGV.shift || '.default'
save_db(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/deinit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def usage
EOS
end

def execute
def execute(opts)
down
Config.config[:envs].delete(envname)
Config.config[:envnames].delete(Config.work_dir)
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/down.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def usage
EOS
end

def execute
def execute(opts)
down
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def usage
EOS
end

def execute
def execute(opts)
return Optimist.die "Already initialized as #{envname}" if envname

name = ARGV.shift
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def usage
EOS
end

def execute
def execute(opts)
ensure_setup
cmd = (ARGV || []).join(' ')
exec "docker exec -ti #{app_container_name} #{cmd}"
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def usage
EOS
end

def execute
def execute(opts)
exec "docker logs -f #{app_container_name}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def usage
EOS
end

def execute
def execute(opts)
cmd = ARGV.shift
if cmd == 'cert-url'
Config.config[:cert_source] = {
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def usage
EOS
end

def execute
def execute(opts)
ensure_setup
cmd = ARGV.shift
valid_cmds = 'ports cert-source http-suffix'
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/shutdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def usage
EOS
end

def execute
def execute(opts)
Config.config[:shared_names].each do |_, container_name|
killrm container_name
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def usage
EOS
end

def execute
def execute(opts)
ensure_setup
setup_app
setup_db
Expand Down

0 comments on commit fa7efb4

Please sign in to comment.