Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimenting with building the commands api for wheelbarrow
- Loading branch information
1 parent
70d8757
commit 7514f34
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |