Class: Opal::CLIOptions

Inherits:
OptionParser
  • Object
show all
Defined in:
opal/lib/opal/cli_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLIOptions

Returns a new instance of CLIOptions



5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
93
# File 'opal/lib/opal/cli_options.rb', line 5

def initialize
  @options = {}

  super do |opts|
    opts.banner = 'Usage: opal [options] -- [programfile]'

    opts.on('-v', '--version', 'Display Opal Version') do |v|
      require 'opal/version'
      puts "Opal v#{Opal::VERSION}"
      exit
    end

    opts.on("-h", "--help", "Show this message") do
      puts opts
      exit
    end

    opts.separator ''
    opts.separator 'Basic Options:'

    opts.on('-I', '--include DIR',
            'Append a load path (may be used more than once)') do |i|
      options[:load_paths] ||= []
      options[:load_paths] << i
    end

    opts.on('-e', '--eval SOURCE', String,
            'One line of script. Several -e\'s allowed. Omit [programfile]') do |source|
      options[:evals] ||= []
      options[:evals] << source
    end

    opts.on('-r', '--require LIBRARY', String,
            'Require the library before executing your script') do |library|
      options[:requires] ||= []
      options[:requires] << library
    end

    opts.on('-s', '--sexp', 'Show Sexps') do
      options[:sexp] = true
    end

    opts.on('-m', '--map', 'Show sourcemap') do
      options[:map] = true
    end

    opts.on('-c', '--compile', 'Compile to JavaScript') do
      options[:compile] = true
    end

    opts.on('-s', '--server [PORT]', 'Start a server (default port: 3000)') do |port|
      options[:server] = port.to_i
    end


    opts.separator ''
    opts.separator 'Compilation Options:'

    opts.on('-M', '--[no-]method-missing', 'Disable method missing') do |val|
      options[:method_missing] = val
    end

    opts.on('-A', '--[no-]arity-check', 'Enable arity check') do |value|
      options[:arity_check] = value
    end

    opts.on('-C', '--[no-]const-missing', 'Disable const missing') do |value|
      options[:const_missing] = value
    end

    dynamic_require_levels = %w[error warning ignore]
    opts.on('-D', '--dynamic-require LEVEL', dynamic_require_levels,
                  'Set levelDynamic require severity') do |level|
      options[:dynamic_require_severity] = level.to_sym
    end

    opts.on('-P', '--no-source-map', 'Disable source map') do |value|
      options[:source_map_enabled] = false
    end

    opts.on('-F', '--file FILE', 'Set filename for compiled code') do |file|
      options[:file] = file
    end

    opts.on("--[no-]irb", "IRB var mode") do |flag|
      options[:irb] = flag
    end
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options



95
96
97
# File 'opal/lib/opal/cli_options.rb', line 95

def options
  @options
end