add "rscons" binary - close #24
This commit is contained in:
parent
4eedea2563
commit
7698fbf618
3
bin/rscons
Executable file
3
bin/rscons
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
require "rscons/cli"
|
||||||
|
|
||||||
|
Rscons::Cli.run(ARGV)
|
78
lib/rscons/cli.rb
Normal file
78
lib/rscons/cli.rb
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
require "rscons"
|
||||||
|
require "optparse"
|
||||||
|
|
||||||
|
module Rscons
|
||||||
|
# Command-Line Interface functionality.
|
||||||
|
module Cli
|
||||||
|
|
||||||
|
# Default files to look for to execute if none specified.
|
||||||
|
DEFAULT_RSCONSFILES = %w[Rsconsfile Rsconsfile.rb]
|
||||||
|
|
||||||
|
class << self
|
||||||
|
|
||||||
|
# Run the Rscons CLI.
|
||||||
|
#
|
||||||
|
# @param argv [Array]
|
||||||
|
# Command-line parameters.
|
||||||
|
#
|
||||||
|
# @return [void]
|
||||||
|
def run(argv)
|
||||||
|
argv = argv.dup
|
||||||
|
rsconsfile = nil
|
||||||
|
|
||||||
|
OptionParser.new do |opts|
|
||||||
|
opts.banner = "Usage: #{$0} [options]"
|
||||||
|
|
||||||
|
opts.separator ""
|
||||||
|
opts.separator "Options:"
|
||||||
|
|
||||||
|
opts.on("-c", "--clean", "Perform clean operation") do
|
||||||
|
Rscons.clean
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.on("-f FILE", "Execute FILE (default Rsconsfile)") do |f|
|
||||||
|
rsconsfile = f
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.on_tail("--version", "Show version") do
|
||||||
|
puts "Rscons version #{Rscons::VERSION}"
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.on_tail("-h", "--help", "Show this help.") do
|
||||||
|
puts opts
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
|
end.parse!(argv)
|
||||||
|
|
||||||
|
if rsconsfile
|
||||||
|
unless File.exists?(rsconsfile)
|
||||||
|
$stderr.puts "Cannot read #{rsconsfile}"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
rsconsfile = DEFAULT_RSCONSFILES.find do |f|
|
||||||
|
File.exists?(f)
|
||||||
|
end
|
||||||
|
unless rsconsfile
|
||||||
|
$stderr.puts "Could not find the Rsconsfile to execute."
|
||||||
|
$stderr.puts "Looked in: [#{DEFAULT_RSCONSFILES.join(", ")}]"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
load rsconsfile
|
||||||
|
rescue Rscons::BuildError => e
|
||||||
|
$stderr.puts e.message
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user