Class: Fig::Command::Options::Parser
- Inherits:
-
Object
- Object
- Fig::Command::Options::Parser
- Defined in:
- lib/fig/command/options/parser.rb
Overview
Command-line processing.
Constant Summary collapse
- SHORT_USAGE =
This class knows way too much about how OptionParser works.
<<-'END_SHORT_USAGE' Short usage summary (use --help-long for everything): Running under Fig: fig [...] [DESCRIPTOR] [-- COMMAND] fig [...] [DESCRIPTOR] --command-extra-args VALUES fig [...] [DESCRIPTOR] --run-command-statement Publishing packages: fig {--publish | --publish-local} [--force] DESCRIPTOR [...] Querying: fig {-g | --get} VARIABLE [DESCRIPTOR] [...] fig --list-dependencies [--list-tree] [--list-all-configs] [DESCRIPTOR] [...] fig --list-variables [--list-tree] [--list-all-configs] [DESCRIPTOR] [...] Standard options (represented as "[...]" above): [--update | --update-if-missing] [--set VARIABLE=VALUE] [--add VARIABLE=VALUE] [--resource PATH] [--archive PATH] [--include DESCRIPTOR] [--include-file PATH:CONFIG] [--override DESCRIPTOR] [--file PATH] [--no-file] (--options for full option list; --help-long for everything) END_SHORT_USAGE
- FULL_USAGE =
<<-'END_FULL_USAGE' Running under Fig: fig [...] [DESCRIPTOR] [-- COMMAND] fig [...] [DESCRIPTOR] --command-extra-args VALUES fig [...] [DESCRIPTOR] --run-command-statement Publishing packages: fig {--publish | --publish-local} [--force] DESCRIPTOR [...] Local repository maintenance: fig --clean DESCRIPTOR [...] Querying: fig {--list-local | --list-remote} [...] fig {-g | --get} VARIABLE [DESCRIPTOR] [...] fig --list-dependencies [...list options...] [DESCRIPTOR] [...] fig --list-variables [...list options...] [DESCRIPTOR] [...] fig --list-configs [DESCRIPTOR] [...] fig --source-package FILE [DESCRIPTOR] [...] fig {-T | --dump-package-definition-text} [DESCRIPTOR] [...] fig --dump-package-definition-parsed [DESCRIPTOR] [...] fig --dump-package-definition-for-command-line [DESCRIPTOR] [...] List options (represented as "[...list options...]" above): [--list-tree | --json | --yaml | --graphviz] [--list-all-configs] Standard options (represented as "[...]" above): [-u | --update | -m | --update-if-missing] --update-lock-response {wait | fail | ignore} [{-s | --set} VARIABLE=VALUE] [{-p | --add | --append} VARIABLE=VALUE] [--resource PATH] [--archive PATH] [{-i | --include} DESCRIPTOR] [--include-file PATH:CONFIG] [--override DESCRIPTOR] [-R | --suppress-retrieves] [--suppress-cleanup-of-retrieves] [--suppress-all-includes] [--suppress-cross-package-includes] [--file PATH] [--no-file] [{-c | --config} CONFIG] [-l | --login] [--log-level LEVEL] [--log-config PATH | --log-to-stdout] [--figrc PATH] [--no-figrc] [--no-remote-figrc] [--suppress-vcs-comments-in-published-packages] [--suppress-warning-include-statement-missing-version] [--suppress-warning-unused-retrieve] Information: fig --help fig --help-long fig --options fig {-v | --version | --version-plain} A DESCRIPTOR looks like <package name>[/<version>][:<config>] e.g. "foo", "foo/1.2.3", and "foo/1.2.3:default". Whether ":<config>" and "/<version>" are required or allowed is dependent upon what your are doing. Environment variables: FIG_REMOTE_URL location of remote repository, required for remote operations FIG_HOME path to local repository, defaults to $HOME/.fighome FIG_SVN_EXECUTABLE path to svn executable, set to empty string to suppress use of Subversion FIG_GIT_EXECUTABLE path to git executable, set to empty string to suppress use of Git END_FULL_USAGE
Instance Method Summary collapse
- #add_argument_description(options, description) ⇒ Object
- #full_help ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #on(*arguments, &block) ⇒ Object
- #on_head(*arguments, &block) ⇒ Object
- #on_tail(*arguments, &block) ⇒ Object
- #options_message ⇒ Object
- #parse!(argv) ⇒ Object
- #raise_invalid_argument(option, value, description = nil) ⇒ Object
- #separator(string) ⇒ Object
- #short_help ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
126 127 128 129 130 131 132 |
# File 'lib/fig/command/options/parser.rb', line 126 def initialize() @switches = {} @argument_description = {} @parser = OptionParser.new @parser. = "#{FULL_USAGE}\nAll options:\n\n" end |
Instance Method Details
#add_argument_description(options, description) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/fig/command/options/parser.rb', line 134 def add_argument_description(, description) if .is_a? Array .each do |option| @argument_description[option] = description end else @argument_description[] = description end return end |
#full_help ⇒ Object
188 189 190 |
# File 'lib/fig/command/options/parser.rb', line 188 def full_help() return @parser.help end |
#on(*arguments, &block) ⇒ Object
158 159 160 161 162 163 164 165 166 |
# File 'lib/fig/command/options/parser.rb', line 158 def on(*arguments, &block) switch_array = make_switch_array(arguments, block) return if not switch_array @parser.top.append(*switch_array) return end |
#on_head(*arguments, &block) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/fig/command/options/parser.rb', line 148 def on_head(*arguments, &block) switch_array = make_switch_array(arguments, block) return if not switch_array @parser.top.prepend(*switch_array) return end |
#on_tail(*arguments, &block) ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/fig/command/options/parser.rb', line 174 def on_tail(*arguments, &block) switch_array = make_switch_array(arguments, block) return if not switch_array @parser.base.append(*switch_array) return end |
#options_message ⇒ Object
192 193 194 |
# File 'lib/fig/command/options/parser.rb', line 192 def () return @parser.summarize('') end |
#parse!(argv) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/fig/command/options/parser.rb', line 196 def parse!(argv) begin @parser.parse!(argv) rescue OptionParser::InvalidArgument => error raise_invalid_argument(error.args[0], error.args[1]) rescue OptionParser::MissingArgument => error raise_missing_argument(error.args[0]) rescue OptionParser::InvalidOption => error raise Fig::Command::OptionError.new( "Unknown option #{error.args[0]}.\n\n#{SHORT_USAGE}" ) rescue OptionParser::ParseError => error raise Fig::Command::OptionError.new(error.to_s) end return end |
#raise_invalid_argument(option, value, description = nil) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/fig/command/options/parser.rb', line 214 def raise_invalid_argument(option, value, description = nil) # *sigh* OptionParser does not raise MissingArgument for the case of an # option with a required value being followed by another option. It # assigns the next option as the value instead. E.g. for # # fig --set --get FOO # # it assigns "--get" as the value of the "--set" option. if @switches.has_key? value raise_missing_argument(option) end description ||= @argument_description[option] if description.nil? description = '' else description = ' ' + description end raise Fig::Command::OptionError.new( %Q<Invalid value for #{option}: "#{value}"#{description}> ) end |
#separator(string) ⇒ Object
168 169 170 171 172 |
# File 'lib/fig/command/options/parser.rb', line 168 def separator(string) @parser.separator string return end |
#short_help ⇒ Object
184 185 186 |
# File 'lib/fig/command/options/parser.rb', line 184 def short_help() return SHORT_USAGE end |