class DevDock::Options
Handles parsing options with the following syntax: dev_dock subcommand [options..] image [command..]
Attributes
environment[R]
error[R]
host_home[R]
image_name[R]
run_command[R]
subcommand[R]
volumes[R]
Public Class Methods
new(argv)
click to toggle source
# File lib/dev_dock/options.rb, line 13 def initialize(argv) @volumes = [] @environment = [] @subcommand = nil @error = nil @image_name = nil @host_home = nil @argv = argv @run_command = ['tmux', 'new'] end
Public Instance Methods
inspect()
click to toggle source
# File lib/dev_dock/options.rb, line 89 def inspect "Subcommand: #{@subcommand}, Image: #{@image_name}, Volumes: #{@volumes}, Environment: #{@environment}, Run Command: #{@run_command}" end
parse()
click to toggle source
# File lib/dev_dock/options.rb, line 24 def parse parse_subcommand if not @error if @subcommand == "start" parse_start else parse_end end end parse_env end
parse_end()
click to toggle source
# File lib/dev_dock/options.rb, line 42 def parse_end if @argv.length != 2 @error = 'Invalid number of arguments' else @image_name = @argv[1] end end
parse_env()
click to toggle source
# File lib/dev_dock/options.rb, line 38 def parse_env @host_home = ENV['DEV_DOCK_HOST_HOME'] || ENV['HOME'] end
parse_start()
click to toggle source
# File lib/dev_dock/options.rb, line 50 def parse_start parser = OptionParser.new 'Usage: dev_dock start [options..] image [command..]' parser.on('-e', '--env ENVIRONMENT') do |env| self.environment.push(env) end parser.on('-v', '--volume VOLUME') do |volume| self.volumes.push(volume) end argv = @argv.slice(1, @argv.length - 1) begin parser.parse!(argv) rescue OptionParser::ParseError => err @error = err.reason end if not @error if argv.length == 0 @error = 'Missing argument: image' else @image_name = argv.shift() if argv.length > 0 @run_command = argv end end end end
parse_subcommand()
click to toggle source
# File lib/dev_dock/options.rb, line 78 def parse_subcommand arg = @argv[0] if arg == 'start' or arg == 's' @subcommand = 'start' elsif arg == 'purge' or arg == 'p' @subcommand = 'purge' else @error = "Invalid subcommand #{arg}" end end