Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Slop "no-" prefix feature #121

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions bin/earthquake
Original file line number Diff line number Diff line change
@@ -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?

Expand All @@ -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{
_ _ _
Expand Down
2 changes: 1 addition & 1 deletion lib/earthquake/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def start(options = {})
end
end

reconnect unless options[:'no-stream'] == true
reconnect if options[:stream]

trap('INT') { stop }
end
Expand Down