Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#command(command, &block) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/git_command.rb', line 1

def command command, &block
  temp_args = ARGV.dup
  first = temp_args.shift

  args = []
  options = {}

  is_option = false
  option = ""

  param = false
  temp_args.each do |arg|
    if is_option
      options[option.to_sym] = arg
      is_option = false
    elsif option?(arg)
      is_option = true
      option = arg.gsub /--/, ''
    elsif flag?(arg)
      options[arg] = true
    else
      args << arg
    end
  end

  args = [ nil ] if args == []

  if first == command.to_s
    block.call *args, **options
  end
end