diff options
Diffstat (limited to 'vendor/bundle/ruby/3.4.0/gems/mercenary-0.4.0/lib/mercenary/program.rb')
| -rw-r--r-- | vendor/bundle/ruby/3.4.0/gems/mercenary-0.4.0/lib/mercenary/program.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/bundle/ruby/3.4.0/gems/mercenary-0.4.0/lib/mercenary/program.rb b/vendor/bundle/ruby/3.4.0/gems/mercenary-0.4.0/lib/mercenary/program.rb new file mode 100644 index 0000000..a8d0c52 --- /dev/null +++ b/vendor/bundle/ruby/3.4.0/gems/mercenary-0.4.0/lib/mercenary/program.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +module Mercenary + class Program < Command + attr_reader :optparse + attr_reader :config + + # Public: Creates a new Program + # + # name - the name of the program + # + # Returns nothing + def initialize(name) + @config = {} + super(name) + end + + # Public: Run the program + # + # argv - an array of string args (usually ARGV) + # + # Returns nothing + def go(argv) + logger.debug("Using args passed in: #{argv.inspect}") + + cmd = nil + + @optparse = OptionParser.new do |opts| + cmd = super(argv, opts, @config) + end + + begin + @optparse.parse!(argv) + rescue OptionParser::InvalidOption => e + logger.error "Whoops, we can't understand your command." + logger.error e.message.to_s + logger.error "Run your command again with the --help switch to see available options." + abort + end + + logger.debug("Parsed config: #{@config.inspect}") + + begin + cmd.execute(argv, @config) + rescue StandardError => e + if cmd.trace + raise e + else + logger.error e.message + abort + end + end + end + end +end |
