diff --git a/lib/wheelbarrow/command.rb b/lib/wheelbarrow/command.rb new file mode 100644 index 0000000..8ee9796 --- /dev/null +++ b/lib/wheelbarrow/command.rb @@ -0,0 +1,46 @@ +module Wheelbarrow + def Command cmd_name, args + Commands.const_get(cmd_name.capitalize).new args + end + + module Commands + class Command + def initialize args + @args = parse_args args + end + + protected + + def self.flag name, options = {} + end + + private + + def parse_args args + flags = [] + args_enum = args.to_enum + arg = '' + loop do + begin + arg = args_enum.next + rescue StopIteration + break + end + if arg.include? "=" + arg_name, arg_val = arg.split "=" + flags << [strip_dashes(arg_name), arg_val] + elsif arg.start_with? '-' + flags << [strip_dashes(arg)] + else + flags.last << arg + end + end + flags + end + + def strip_dashes str + str[/-*([^-]*)/,1] + end + end + end +end diff --git a/lib/wheelbarrow/commands/setup.rb b/lib/wheelbarrow/commands/setup.rb new file mode 100644 index 0000000..3150d4e --- /dev/null +++ b/lib/wheelbarrow/commands/setup.rb @@ -0,0 +1,8 @@ +module Wheelbarrow + module Commands + class Setup < Command + flag :app_dir, short: :a, description: "Path to the directory where the app should be deployed" + flag :repo, short: :r, description: "Path to the Git repository where the Git hook should be installed" + end + end +end