Module: Rscons::Cli

Defined in:
lib/rscons/cli.rb

Overview

Command-Line Interface functionality.

Constant Summary collapse

DEFAULT_RSCONSFILES =

Default files to look for to execute if none specified.

%w[Rsconsfile Rsconsfile.rb]

Class Method Summary collapse

Class Method Details

.run(argv) ⇒ void

This method returns an undefined value.

Run the Rscons CLI.

Parameters:

  • argv (Array)

    Command-line parameters.

[View source]

19
20
21
22
23
24
25
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
# File 'lib/rscons/cli.rb', line 19

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("-j NTHREADS", "Use NTHREADS parallel jobs (local default #{Rscons.n_threads})") do |n_threads|
      Rscons.n_threads = n_threads.to_i
    end

    opts.on("-r", "--color MODE", "Set color mode (off, auto, force)") do |color_mode|
      case color_mode
      when "off"
        Rscons.do_ansi_color = false
      when "force"
        Rscons.do_ansi_color = true
      end
    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)

  argv.each do |arg|
    if arg =~ /^([^=]+)=(.*)$/
      Rscons.vars[$1] = $2
    end
  end

  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
    exit 1
  end

  exit 0
end