@@ -30,17 +30,6 @@ def run(args = ARGV)
30
30
help
31
31
end
32
32
33
- def help
34
- say "NAME"
35
- say " git-cmd – Git Commander allows running custom git commands from a centralized location."
36
- say "VERSION"
37
- say " #{ GitCommander ::VERSION } "
38
- say "USAGE"
39
- say " git-cmd command [command options] [arguments...]"
40
- say "COMMANDS"
41
- say registry . commands . keys . join ( ", " )
42
- end
43
-
44
33
def say ( message )
45
34
output . puts message
46
35
end
@@ -51,25 +40,7 @@ def say(message)
51
40
# @param arguments [Array] the command line arguments
52
41
# @return options [Array] the GitCommander::Command options with values
53
42
def parse_command_options! ( command , arguments )
54
- valid_arguments_for_command = command . arguments . map { |arg | "[#{ arg . name } ]" } . join ( " " )
55
-
56
- parser = OptionParser . new do |opts |
57
- opts . banner = "USAGE:\n git-cmd #{ command . name } [command options] #{ valid_arguments_for_command } "
58
- opts . separator ""
59
- opts . separator "COMMAND OPTIONS:" if command . flags . any? || command . switches . any?
60
-
61
- command . flags . each do |flag |
62
- opts . on ( "-#{ flag . name [ 0 ] } " , command_line_flag_formatted_name ( flag ) , flag . description . to_s ) do |f |
63
- flag . value = f
64
- end
65
- end
66
-
67
- command . switches . each do |switch |
68
- opts . on ( "-#{ switch . name [ 0 ] } " , "--[no-]#{ switch . name } " , switch . description ) do |s |
69
- switch . value = s
70
- end
71
- end
72
- end
43
+ parser = configure_option_parser_for_command ( command )
73
44
parser . parse! ( arguments )
74
45
75
46
# Add arguments to options to pass to defined commands
@@ -86,6 +57,46 @@ def parse_command_options!(command, arguments)
86
57
87
58
private
88
59
60
+ def help
61
+ say "NAME"
62
+ say " git-cmd – Git Commander allows running custom git commands from a centralized location."
63
+ say "VERSION"
64
+ say " #{ GitCommander ::VERSION } "
65
+ say "USAGE"
66
+ say " git-cmd command [command options] [arguments...]"
67
+ say "COMMANDS"
68
+ say registry . commands . keys . join ( ", " )
69
+ end
70
+
71
+ def configure_option_parser_for_command ( command )
72
+ valid_arguments_for_command = command . arguments . map { |arg | "[#{ arg . name } ]" } . join ( " " )
73
+
74
+ OptionParser . new do |opts |
75
+ opts . banner = "USAGE:\n git-cmd #{ command . name } [command options] #{ valid_arguments_for_command } "
76
+ opts . separator ""
77
+ opts . separator "COMMAND OPTIONS:" if command . flags . any? || command . switches . any?
78
+
79
+ configure_flags_for_option_parser_and_command ( opts , command )
80
+ configure_switches_for_option_parser_and_command ( opts , command )
81
+ end
82
+ end
83
+
84
+ def configure_flags_for_option_parser_and_command ( option_parser , command )
85
+ command . flags . each do |flag |
86
+ option_parser . on ( "-#{ flag . name [ 0 ] } " , command_line_flag_formatted_name ( flag ) , flag . description . to_s ) do |f |
87
+ flag . value = f
88
+ end
89
+ end
90
+ end
91
+
92
+ def configure_switches_for_option_parser_and_command ( option_parser , command )
93
+ command . switches . each do |switch |
94
+ option_parser . on ( "-#{ switch . name [ 0 ] } " , "--[no-]#{ switch . name } " , switch . description ) do |s |
95
+ switch . value = s
96
+ end
97
+ end
98
+ end
99
+
89
100
def command_line_flag_formatted_name ( flag )
90
101
"--#{ underscore_to_kebab ( flag . name ) } #{ flag . name . upcase } "
91
102
end
0 commit comments