diff --git a/bin/earthquake b/bin/earthquake index 9868b58..47060a1 100755 --- a/bin/earthquake +++ b/bin/earthquake @@ -1,20 +1,38 @@ #!/usr/bin/env ruby require 'slop' +require 'stringio' argv = ARGV.dup -slop = Slop.new(:strict => true, :help => true) +io = StringIO.new +slop = Slop.new(:strict => true, :help => true, :exit_on_help => false, :io => io) slop.banner "Usage: earthquake [options] [directory]" slop.on :d, :debug, 'Enable debug mode' -slop.on :n, :'no-logo', 'No Logo' -slop.on :c, :command, "Invoke a command and exit", true -slop.on :'--no-stream', "No stream mode" +slop.on :l, :logo, 'Show Logo', default: true +slop.on :n, 'No Logo (deprecated)' +slop.on :c, :command=, "Invoke a command and exit" +slop.on :stream, "Stream mode", default: true begin slop.parse!(argv) + (help = io.string).each_line do |line| + if m = /\A.{8}--(\S+ {5})/.match(line) + name = m[1].rstrip + if name != "help" and !slop.options[name.to_sym].expects_argument? + puts line.sub(m[1], "[no-]" + name) + next + end + end + puts line + end + exit unless help.empty? rescue => e puts e exit! end options = slop.to_hash +if options.delete(:n) + warn "-n is deprecated. use --no-logo instead." + options.delete(:logo) +end options.delete(:help) options[:dir] = argv.shift unless argv.empty? @@ -23,9 +41,9 @@ $:.unshift Pathname.new(__FILE__).realpath.join('../../lib') if $0 == __FILE__ require "earthquake/version" command = options.delete(:command) -no_logo = options.delete(:'no-logo') +logo = options.delete(:logo) -if !no_logo && !command +if logo && !command print "\e[31m" puts %q{ _ _ _ diff --git a/lib/earthquake/core.rb b/lib/earthquake/core.rb index 2b483eb..d981998 100644 --- a/lib/earthquake/core.rb +++ b/lib/earthquake/core.rb @@ -148,7 +148,7 @@ def start(options = {}) end end - reconnect unless options[:'no-stream'] == true + reconnect if options[:stream] trap('INT') { stop } end