Module: ArgParser
- Defined in:
- lib/canuby/argparser.rb
Overview
Parses command line arguments
Class Method Summary collapse
-
.min(_args) ⇒ Object
Parse minimal arguments.
- .parse(args) ⇒ Object
Class Method Details
.min(_args) ⇒ Object
Parse minimal arguments. Usefull if you just need the all build tasks.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/canuby/argparser.rb', line 105 def self.min(_args) = OpenStruct.new .config_version = Canuby::CONFIG_VERSION .target = 'thirdparty' .yml_file = 'canuby.yml' OptionParser.new do |opts| opts.on('-c', '--config', 'Use a custom config file.') do Rake.application.tasks.each do |c| .yml_file = c end end end end |
.parse(args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/canuby/argparser.rb', line 26 def self.parse(args) = { 'config_version' => Canuby::CONFIG_VERSION, 'base_dir' => '3rdparty', 'target' => 'thirdparty', 'yml_file' => 'canuby.yml' } = OpenStruct.new() parser = OptionParser.new do |opts| opts. = "\n" opts.separator 'Usage: canuby [options]' opts.separator "\nBuild options:" opts.on('-c', '--config', 'Use a custom config file.') do Rake.application.tasks.each do |c| .yml_file = c end end opts.on('-d', '--dir [directory]', 'Specify a working directory') do |dir| .base_dir = dir end opts.on('-t', '--target [target]', 'Choose a target to build') do |t| .target = if t.to_s.match?(/^thirdparty:/) t else "thirdparty:#{t}" end end opts.separator "\nOther @options:" opts.on('--check-config', 'Checks only if the config is valid.') do .only_check_config = true end opts.on('--debug', 'Show debug information in console') do .debug = true end opts.on('--ignore-config-file', 'Ignore the config file.') do .ignore_config_file = true end opts.on('-l', '--list', 'List all available targets') do .list = true end opts.on('--list-all', 'List all available tasks') do .list_all = true end opts.on('-v', '--verbose', 'Be more verbose and show debug information in console') do .debug = true end opts.separator "\n" opts.on_tail('-h', '--help', 'Show this help message') do puts opts exit end opts.on_tail('--version', 'Show version') do puts Canuby::VERSION exit end end begin parser.parse!(args) rescue OptionParser::InvalidOption => e if File.basename(__FILE__) == 'Rakefile' || File.basename($PROGRAM_NAME) == 'rake_test_loader.rb' || e.to_s.split(': ')[1] == '--profile' puts 'hi' # return else puts('Canuby does not understand that argument. We just assume it belongs to ruby.') puts(e) end end end |