Skip to content

Commit

Permalink
Experimenting with building the commands api for wheelbarrow
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgrouleff committed Oct 7, 2012
1 parent 70d8757 commit 7514f34
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
46 changes: 46 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions 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

0 comments on commit 7514f34

Please sign in to comment.