lib/opal/cli_options.rb in opal-1.6.1 vs lib/opal/cli_options.rb in opal-1.7.0.rc1

- old
+ new

@@ -11,10 +11,14 @@ self.banner = 'Usage: opal [options] -- [programfile]' separator '' + on('--repl', 'Run the Opal REPL') do + options[:repl] = true + end + on('-v', '--verbose', 'print version number, then turn on verbose mode') do print_version exit if ARGV.empty? options[:verbose] = true end @@ -30,26 +34,17 @@ on('--version', 'Print the version') do print_version exit end - on('--repl', 'Run the Opal REPL') do - options[:repl] = true - end - on('-h', '--help', 'Show this message') do puts self exit end section 'Basic Options:' - on('-I', '--include DIR', 'Append a load path (may be used more than once)') do |i| - options[:load_paths] ||= [] - options[:load_paths] << i - end - on('-e', '--eval SOURCE', String, 'One line of script. Several -e\'s allowed. Omit [programfile]' ) do |source| options[:evals] ||= [] options[:evals] << source @@ -67,10 +62,15 @@ ) do |library| options[:rbrequires] ||= [] options[:rbrequires] << library end + on('-I', '--include DIR', 'Append a load path (may be used more than once)') do |i| + options[:load_paths] ||= [] + options[:load_paths] << i + end + on('-s', '--stub FILE', String, 'Stubbed files will be compiled as empty files') do |stub| options[:stubs] ||= [] options[:stubs] << stub end @@ -84,60 +84,84 @@ options[:gems] << g end section 'Running Options:' - on('--sexp', 'Show Sexps') do - options[:sexp] = true + on('-R', '--runner RUNNER', Opal::CliRunners.to_h.keys, 'Choose the runner:', "nodejs (default), #{(Opal::CliRunners.to_h.keys - %i[nodejs compiler]).join(', ')}") do |runner| + options[:runner] = runner.to_sym end - on('--debug-source-map', 'Debug source map') do - options[:debug_source_map] = true + on('--server-port PORT', 'Set the port for the server runner (default port: 3000)') do |port| + options[:runner_options] ||= {} + options[:runner_options][:port] = port.to_i end + on('--runner-options JSON', 'Set options specific to the selected runner as a JSON string (e.g. port for server)') do |json_options| + require 'json' + runner_options = JSON.parse(json_options, symbolize_names: true) + options[:runner_options] ||= {} + options[:runner_options].merge!(runner_options) + end + + section 'Builder Options:' + on('-c', '--compile', 'Compile to JavaScript') do options[:runner] = :compiler end - on('-R', '--runner RUNNER', Opal::CliRunners.to_h.keys, "Choose the runner: nodejs (default), #{(Opal::CliRunners.to_h.keys - [:nodejs]).join(', ')}") do |runner| - options[:runner] = runner.to_sym + on('-o', '--output FILE', 'Output JavaScript to FILE') do |file| + options[:output] = File.open(file, 'w') end - on('--runner-options JSON', 'Set options specific to the selected runner as a JSON string (e.g. port for server)') do |json_options| - require 'json' - runner_options = JSON.parse(json_options, symbolize_names: true) + on('-P', '--map FILE', 'Output source map to FILE') do |file| options[:runner_options] ||= {} - options[:runner_options].merge!(runner_options) + options[:runner_options][:map_file] = file end - on('--server-port PORT', '(deprecated, use --runner-options) Set the port for the server runner (default port: 3000)') do |port| + on('--no-source-map', "Don't append source map to a compiled file") do options[:runner_options] ||= {} - options[:runner_options][:port] = port.to_i + options[:runner_options][:no_source_map] = true end - on('-E', '--no-exit', 'Do not append a Kernel#exit at the end of file') do - options[:no_exit] = true + on('--watch', 'Run the compiler in foreground, recompiling every filesystem change') do + options[:runner_options] ||= {} + options[:runner_options][:watch] = true end - section 'Compilation Options:' + on('--no-cache', 'Disable filesystem cache') do + options[:no_cache] = true + end - on('-M', '--no-method-missing', 'Disable method missing') do - options[:method_missing] = false + on('-L', '--library', 'Compile only required libraries. Omit [programfile] and [-e]. Assumed [-cOE].') do + options[:lib_only] = true + options[:no_exit] = true + options[:compile] = true + options[:skip_opal_require] = true end on('-O', '--no-opal', 'Disable implicit `require "opal"`') do options[:skip_opal_require] = true end - on('-A', '--arity-check', 'Enable arity check') do - options[:arity_check] = true + on('-E', '--no-exit', 'Do not append a Kernel#exit at the end of file') do + options[:no_exit] = true end - on('-V', 'Enable inline Operators') do - options[:inline_operators] = true + section 'Compiler Options:' + + on('--use-strict', 'Enables JavaScript\'s strict mode (i.e., adds \'use strict\'; statement)') do + options[:use_strict] = true end + on('--esm', 'Wraps compiled bundle as for ES6 module') do + options[:esm] = true + end + + on('-A', '--arity-check', 'Enable arity check') do + options[:arity_check] = true + end + dynamic_require_levels = %w[error warning ignore] on('-D', '--dynamic-require LEVEL', dynamic_require_levels, 'Set level of dynamic require severity.', "(default: error, values: #{dynamic_require_levels.join(', ')})" ) do |level| @@ -150,56 +174,46 @@ "(default: error, values: #{missing_require_levels.join(', ')})" ) do |level| options[:missing_require_severity] = level.to_sym end - on('-P', '--map FILE', 'Output path to FILE') do |file| - options[:runner_options] ||= {} - options[:runner_options][:map_file] = file + on('--enable-source-location', 'Compiles source location for each method definition.') do + options[:enable_source_location] = true end - on('--no-source-map', "Don't append source map to a compiled file") do - options[:runner_options] ||= {} - options[:runner_options][:no_source_map] = true + on('--parse-comments', 'Compiles comments for each method definition.') do + options[:parse_comments] = true end - on('-F', '--file FILE', 'Set filename for compiled code') do |file| - options[:file] = file + on('--enable-file-source-embed', 'Embeds file sources to be accessed by applications.') do + options[:enable_file_source_embed] = true end - on('-L', '--library', 'Compile only required libraries. Omit [programfile] and [-e]. Assumed [-cOE].') do - options[:lib_only] = true - options[:no_exit] = true - options[:compile] = true - options[:skip_opal_require] = true - end - on('--irb', 'Enable IRB var mode') do options[:irb] = true end - on('--enable-source-location', 'Compiles source location for each method definition.') do - options[:enable_source_location] = true + on('-M', '--no-method-missing', 'Disable method missing') do + options[:method_missing] = false end - on('--enable-file-source-embed', 'Embeds file sources to be accessed by applications.') do - options[:enable_file_source_embed] = true + on('-F', '--file FILE', 'Set filename for compiled code') do |file| + options[:file] = file end - on('--use-strict', 'Enables JavaScript\'s strict mode (i.e., adds \'use strict\'; statement)') do - options[:use_strict] = true + on('-V', '(deprecated; always enabled) Enable inline Operators') do + warn '* -V is deprecated and has no effect' + options[:inline_operators] = true end - on('--parse-comments', 'Compiles comments for each method definition.') do - options[:parse_comments] = true - end + section 'Debug Options:' - on('--no-cache', 'Disable filesystem cache') do - options[:no_cache] = true + on('--sexp', 'Show Sexps') do + options[:sexp] = true end - on('--esm', 'Wraps compiled bundle as for ES6 module(requires -c or -L)') do - options[:esm] = true + on('--debug-source-map', 'Debug source map') do + options[:debug_source_map] = true end separator '' end