Class: Skylark::ArgumentConfiguration
- Inherits:
-
Configuration
- Object
- Skylark::ArgumentConfiguration
- Defined in:
- lib/skylark/argument_configuration.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_verbosity_option(parser) ⇒ Object
- #define_options(parser) ⇒ Object
-
#initialize ⇒ ArgumentConfiguration
constructor
A new instance of ArgumentConfiguration.
Constructor Details
#initialize ⇒ ArgumentConfiguration
Returns a new instance of ArgumentConfiguration.
31 32 33 34 35 36 |
# File 'lib/skylark/argument_configuration.rb', line 31 def initialize super self[:spec_files] = [] self[:logger_level] = :warn end |
Class Method Details
.parse(argv) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/skylark/argument_configuration.rb', line 8 def self.parse(argv) configuration = self.new args = OptionParser.new do |parser| configuration.(parser) parser.parse!(argv) if argv.empty? puts parser $stderr.puts "Expected at least one filename; exiting." exit end configuration[:spec_files] = argv.select do |argument| argument_as_filename = File.(argument, Dir.pwd) File.readable?(argument_as_filename) end end configuration end |
Instance Method Details
#add_verbosity_option(parser) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/skylark/argument_configuration.rb', line 61 def add_verbosity_option(parser) parser.on('-d', '--debug-level LEVEL', 'Sets the debugging level to LEVEL.') do |level| self[:logger_level] = level.downcase.to_sym end parser.on('-v', '--verbose', 'Sets the debugging level to a sensible verbose default.') do self[:logger_level] = :debug end end |
#define_options(parser) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/skylark/argument_configuration.rb', line 38 def (parser) parser. = "Usage: \#{$0} [options] [--] <filename> [<filename>...]\n" parser.separator "" parser.separator "OPTIONS:" add_verbosity_option(parser) parser.separator "" parser.separator "GENERAL OPTIONS:" parser.on_tail('-h', '--help', 'Show this usage message.') do puts parser exit end parser.on_tail('--version', 'Print the version.') do puts Skytrain::VERSION exit end end |