require 'optparse' module Soaring class CLI def self.start(argv) @project_folder = Dir.pwd command, options = self.parse puts "executing #{command} with #{options}" if options[:verbose] self.send("execute_#{command}",options) end private def self.execute_init(options) initializer = Initializer.new(options) initializer.initialize_project(@project_folder) end def self.execute_update(options) initializer = Initializer.new(options) initializer.initialize_project(@project_folder) end def self.execute_run(options) runner = Runner.new(options) runner.run(@project_folder) end def self.execute_package(options) packager = Packager.new(options) packager.package(@project_folder) end def self.parse options = {} opt_parser = OptionParser.new do |opt| opt.banner = "Usage: soaring COMMAND [OPTIONS]" opt.separator "" opt.separator "Commands" opt.separator " init: create a new soar service component in the current folder" opt.separator " update: update the soar service component in the current folder" opt.separator " run: run soar service locally" opt.separator " package: package the service component for deployment" opt.separator "" opt.separator "Options" opt.on("-v","--verbose","more verbose output of the process") do options[:verbose] = true end opt.on("-e","--environment ENVIRONMENT","environment you want the service to run in") do |environment| options[:environment] = environment end opt.on("-p","--port PORT","port to which the service component run must bind to") do |port| options[:port] = port end opt.on("-r","--soar_sc_refspec REF_SPEC","git reference spec for the soar_sc to base your init on") do |soar_sc_refspec| options[:soar_sc_refspec] = soar_sc_refspec end opt.on("-i","--ignore_git_checks","ignore checks ensuring your repo is up to date") do options[:ignore_git_checks] = true puts "Warning: Ignoring git repo checks" end opt.on("-h","--help","help") do puts opt_parser exit 0 end end opt_parser.parse! command = ARGV[0] valid_commands = ['init', 'update', 'run', 'package'] if not valid_commands.include?(command) puts 'Invalid command' puts opt_parser exit 1 end [command, options] end end end