lib/mireru/command/mireru.rb in mireru-0.0.9 vs lib/mireru/command/mireru.rb in mireru-0.1.0
- old
+ new
@@ -4,11 +4,11 @@
require "mireru/container"
module Mireru
module Command
class Mireru
- USAGE = "Usage: mireru [FILE...]"
+ USAGE = "Usage: mireru [OPTION]... [FILE]..."
class << self
def run(*arguments)
new.run(arguments)
end
@@ -17,21 +17,18 @@
def initialize
@logger = ::Mireru::Logger.new
end
def run(arguments)
- if arguments.empty?
- files = Dir.glob("*")
- file_container = ::Mireru::Container.new(files)
- elsif /\A(-h|--help)\z/ =~ arguments[0]
+ if /\A(-h|--help)\z/ =~ arguments[0]
write_help_message
exit(true)
- else
- files = arguments
- file_container = ::Mireru::Container.new(files)
end
+ files = files_from_arguments(arguments)
+ file_container = ::Mireru::Container.new(files)
+
if file_container.empty?
write_empty_message
exit(false)
end
@@ -40,17 +37,50 @@
Gtk.main
end
private
+ def files_from_arguments(arguments)
+ if arguments.empty?
+ files = Dir.glob("*")
+ elsif /\A(-d|--deep)\z/ =~ arguments[0]
+ arguments.shift
+ if arguments.empty?
+ files = Dir.glob("**/*")
+ else
+ files = []
+ arguments.each do |f|
+ if File.directory?(f)
+ files << Dir.glob("#{f}/**/*")
+ else
+ files << f
+ end
+ end
+ files.flatten!
+ end
+ elsif arguments.all? {|v| File.directory?(v) }
+ files = []
+ arguments.each do |f|
+ files << Dir.glob("#{f}/*")
+ end
+ files.flatten!
+ else
+ files = arguments
+ end
+ files
+ end
+
def write_help_message
message = <<-EOM
#{USAGE}
If no argument, then search current directory.
+Options:
+ -d, --deep: deep search
Keybind:
n: next
p: prev
r: reload
+ e: expand path
q: quit
scroll:
h: left
j: down