bin/contexto in contexto-0.2.4 vs bin/contexto in contexto-0.3.0
- old
+ new
@@ -9,33 +9,32 @@
require 'English'
$stderr.sync = true
options = {}
-options[:console] = false
-options[:bash] = false
-options[:ssh] = false
+options[:connection_type] = false
optparse = OptionParser.new do |opts|
opts.banner = 'Usage: contexto [options]'
opts.on('-c', '--cluster CLUSTER', 'Cluster') { |v| options[:cluster] = v }
opts.on('-s', '--service SERVICE', 'Service') { |v| options[:service] = v }
- opts.on('-t', '--container CONTAINER', 'Container') { |v| options[:container] = v }
- opts.on('-r', '--rake COMMAND', 'Rake command') { |v| options[:rake] = v }
- opts.on('-b', '--console') { options[:console] = true }
- opts.on('-e', '--bash') { options[:bash] = true }
- opts.on('-f', '--ssh') { options[:ssh] = true }
+ opts.on('-v', '--container CONTAINER', 'Container') { |v| options[:container] = v }
+ opts.on('-t', "--type [TYPE]", [:console, :ssh, :bash], "Select connection type (console, ssh, bash)") { |v| options[:connection_type] = v }
+ opts.on_tail("-h", "--help", "Show this message") do
+ puts opts
+ exit
+ end
end
begin
optparse.parse!
- mandatory = []
- missing = mandatory.select { |param| options[param].nil? }
- unless missing.empty?
- raise OptionParser::MissingArgument.new(missing.join(', '))
+ if options[:connection_type] && !options[:container]
+ raise OptionParser::MissingArgument.new("If you want to connect to a container you need to specify a container name.")
+ puts "\n"
end
-rescue OptionParser::InvalidOption, OptionParser::MissingArgument
- puts $ERROR_INFO.to_s
+rescue OptionParser::InvalidOption, OptionParser::InvalidArgument, OptionParser::MissingArgument
+ puts $ERROR_INFO.to_s.capitalize
+ puts "\n"
puts optparse
exit
end
c = Contexto::Contextualize.new(options)