require 'yaml' module AppRb class Cli def initialize(args) @args = args Thread.abort_on_exception = true end def run if @args.count < 2 usage exit end config = Config.new(YAML.load(File.read(@args[0]))) command = @args[1] if AppRb::Util.compare_versions(config.tool_version, AppRb::VERSION) > 0 puts "FATAL: need at least '#{config.tool_version}' tool version but current version is '#{AppRb::VERSION}'" exit -1 end if command == "deploy" || command == "d" Command.new(config).deploy(@args[2]) elsif command == "status" || command == "s" Command.new(config).status elsif command == "restart" Command.new(config).restart elsif command == "clean" Command.new(config).clean elsif command == "stop" Command.new(config).stop else puts "FATAL: unknown command '#{command}'" exit -1 end end private def usage puts "Just deploy your apps with docker and consul. Nothing else." puts "Version: #{AppRb::VERSION}" puts "" puts " app-rb " puts "" puts " deploy [hash] - deploy new version of app" puts " status - status of app" puts " stop - stop app" end end end