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

Instance Method Details

#collect_tasksObject



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_optionsObject



105
106
107
# File 'lib/buildr/core/application_cli.rb', line 105

def command_line_options
  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'
    options.show_prereqs = true
    options.show_task_pattern = Regexp.new(value || '.')
  when '--nosearch', '--quiet', '--trace'
    super
  end
end

#helpObject



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_optionsObject



77
78
79
80
# File 'lib/buildr/core/application_cli.rb', line 77

def parse_options
  opts = GetoptLong.new(*command_line_options)
  opts.each { |opt, value| do_option(opt, value) }
end

#usageObject



113
114
115
116
117
118
# File 'lib/buildr/core/application_cli.rb', line 113

def usage
  puts version
  puts
  puts 'Usage:'
  puts '  buildr [options] [tasks] [name=value]'
end

#versionObject



109
110
111
# File 'lib/buildr/core/application_cli.rb', line 109

def version
  "Buildr #{Buildr::VERSION} #{RUBY_PLATFORM[/java/] && '(JRuby '+JRUBY_VERSION+')'}"
end