Module: Buildr::CommandLineInterface
- Included in:
- Application
- Defined in:
- lib/buildr/core/application_cli.rb
Constant Summary collapse
- OPTIONS =
:nodoc:
[ # :nodoc: ['--help', '-h', GetoptLong::NO_ARGUMENT, 'Display this help message.'], ['--nosearch', '-n', GetoptLong::NO_ARGUMENT, 'Do not search parent directories for the buildfile.'], ['--quiet', '-q', GetoptLong::NO_ARGUMENT, 'Do not log messages to standard output.'], ['--buildfile', '-f', GetoptLong::REQUIRED_ARGUMENT, 'Use FILE as the buildfile.'], ['--require', '-r', GetoptLong::REQUIRED_ARGUMENT, 'Require MODULE before executing buildfile.'], ['--trace', '-t', GetoptLong::NO_ARGUMENT, 'Turn on invoke/execute tracing, enable full backtrace.'], ['--prereqs', '-P', GetoptLong::OPTIONAL_ARGUMENT, 'Display tasks and dependencies, then exit.'], ['--version', '-v', GetoptLong::NO_ARGUMENT, 'Display the program version.'], ['--environment', '-e', GetoptLong::REQUIRED_ARGUMENT, 'Environment name (e.g. development, test, production).'] ]
Instance Method Summary collapse
- #collect_tasks ⇒ Object
- #command_line_options ⇒ Object
- #do_option(opt, value) ⇒ Object
- #help ⇒ Object
- #parse_options ⇒ Object
- #usage ⇒ Object
- #version ⇒ Object
Instance Method Details
#collect_tasks ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/buildr/core/application_cli.rb', line 65 def collect_tasks top_level_tasks.clear ARGV.each do |arg| if arg =~ /^(\w+)=(.*)$/ ENV[$1.upcase] = $2 else top_level_tasks << arg end end top_level_tasks.push("default") if top_level_tasks.size == 0 end |
#command_line_options ⇒ Object
105 106 107 |
# File 'lib/buildr/core/application_cli.rb', line 105 def OPTIONS.collect { |lst| lst[0..-2] } end |
#do_option(opt, value) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/buildr/core/application_cli.rb', line 82 def do_option(opt, value) case opt when '--help' help exit when '--buildfile' rakefiles.clear rakefiles << value when '--version' puts version exit when '--environment' ENV['BUILDR_ENV'] = value when '--require' requires << value when '--prereqs' .show_prereqs = true .show_task_pattern = Regexp.new(value || '.') when '--nosearch', '--quiet', '--trace' super end end |
#help ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/buildr/core/application_cli.rb', line 120 def help usage puts puts 'Options:' OPTIONS.sort.each do |long, short, mode, desc| if mode == GetoptLong::REQUIRED_ARGUMENT if desc =~ /\b([A-Z]{2,})\b/ long = long + "=#{$1}" end end printf " %-20s (%s)\n", long, short printf " %s\n", desc end puts puts 'For help with your buildfile:' puts ' buildr help' end |
#parse_options ⇒ Object
77 78 79 80 |
# File 'lib/buildr/core/application_cli.rb', line 77 def opts = GetoptLong.new(*) opts.each { |opt, value| do_option(opt, value) } end |