Module: VerySafeRm::Arg

Defined in:
lib/very_safe_rm/args.rb

Class Method Summary collapse

Class Method Details

.arg(arg) ⇒ Object



16
17
18
19
20
# File 'lib/very_safe_rm/args.rb', line 16

def self.arg(arg)
  return [] unless arg[0] == '-'
  return [arg] if arg[1] == '-'
  arg[1..-1].each_char.each_with_object([]) { |a, obj| obj << "-#{a}" }
end

.parse(argv) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/very_safe_rm/args.rb', line 3

def self.parse(argv)
  a = argv.each_with_object(file: [], args: [], done: false) do |arg, obj|
    if obj[:done] then obj[:file] << arg
    elsif arg == '--' then obj[:done] = true
    elsif arg[0] == '-' then obj[:args].push(*Arg.arg(arg))
    else obj[:file] << arg
    end
  end
  [a[:file], a[:args]]
end