Method: Notes::Options#arg_groups

Defined in:
lib/notes-cli/options.rb

#arg_groups(args) ⇒ Object

Parse ARGV into a directory and list of argument groups For example, given [‘app/’, -f’, ‘refactor’, ‘broken’, ‘–exclude’, ‘tmp’, ‘log’]:

> [ [‘app/’], [‘-f’, ‘refactor’, ‘broken’], [‘–exclude’, ‘tmp’, ‘log’] ]



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/notes-cli/options.rb', line 30

def arg_groups(args)
  result = []
  buf    = []

  # No dir was passed, use default
  if args.empty? || args.first.start_with?('-')
    result << [ Notes.root ]
  end

  args.each do |arg|
    if ALL_FLAGS.include?(arg)
      result << buf unless buf.empty?
      buf = []
    end
    buf << arg
  end

  result << buf
end