Class: Ibex::CLI

Inherits:
Object
  • Object
show all
Includes:
CLICounterexampleOptions, CLIGenerationArtifacts, CLIGenerationErrorMessages, CLIOutputs
Defined in:
lib/ibex/cli.rb

Overview

Command-line pipeline coordinator. rubocop:disable Metrics/ClassLength -- inline type contracts add lines without adding runtime responsibilities.

Defined Under Namespace

Classes: Command, Invocation, ValidateIRCommand

Constant Summary collapse

FEATURE_LOADERS =
{
  CLIAmbiguity: -> { CLIAmbiguity },
  CLIAnalysis: -> { CLIAnalysis },
  CLIImpact: -> { CLIImpact },
  CLIDiagnostics: -> { CLIDiagnostics },
  CLICoverage: -> { CLICoverage },
  CLIConfig: -> { CLIConfig },
  CLIDebug: -> { CLIDebug },
  CLIDocumentation: -> { CLIDocumentation },
  CLIErrorMessages: -> { CLIErrorMessages },
  CLIEquiv: -> { CLIEquiv },
  CLIExplain: -> { CLIExplain },
  CLIFormatting: -> { CLIFormatting },
  CLIFix: -> { CLIFix },
  CLIFuzz: -> { CLIFuzz },
  CLIGrammarTests: -> { CLIGrammarTests },
  CLILSP: -> { CLILSP },
  CLIBisonImport: -> { CLIBisonImport },
  CLIRaccMigration: -> { CLIRaccMigration },
  CLIReduce: -> { CLIReduce },
  CLISamples: -> { CLISamples },
  CLIVerify: -> { CLIVerify },
  CLIIRTools: -> { CLIIRTools },
  CLIWatch: -> { CLIWatch }
}.freeze
COMMANDS =

steep:ignore:start

{ # steep:ignore:start
  "check" => Command.new(:CLIAmbiguity) { |arguments| run_check_command(arguments) },
  "diff" => Command.new(:CLIAnalysis) { |arguments| run_diff_command(arguments) },
  "impact" => Command.new(:CLIImpact) { |arguments| run_impact_command(arguments) },
  "diagnose" => Command.new(:CLIDiagnostics) { |arguments| run_diagnose_command(arguments) },
  "coverage" => Command.new(:CLICoverage) { |arguments| run_coverage_command(arguments) },
  "config" => Command.new(:CLIConfig) { |arguments| run_config_command(arguments) },
  "debug" => Command.new(:CLIDebug) { |arguments| run_debug_command(arguments) },
  "doc" => Command.new(:CLIDocumentation) { |arguments| run_documentation_command(arguments) },
  "errors" => Command.new(:CLIErrorMessages) { |arguments| run_error_messages_command(arguments) },
  "equiv" => Command.new(:CLIEquiv) { |arguments| run_equiv_command(arguments) },
  "explain" => Command.new(:CLIExplain) { |arguments| run_explain_command(arguments) },
  "fmt" => Command.new(:CLIFormatting) { |arguments| run_format_command(arguments) },
  "fix" => Command.new(:CLIFix) { |arguments| run_fix_command(arguments) },
  "fuzz" => Command.new(:CLIFuzz) { |arguments| run_fuzz_command(arguments) },
  "test" => Command.new(:CLIGrammarTests) { |arguments| run_grammar_tests_command(arguments) },
  "lsp" => Command.new(:CLILSP) { |arguments| run_lsp_command(arguments) },
  "import" => Command.new(:CLIBisonImport) { |arguments| run_bison_import_command(arguments) },
  "metrics" => Command.new(:CLIAnalysis) { |arguments| run_metrics_command(arguments) },
  "migrate-check" => Command.new(:CLIRaccMigration) { |arguments| run_migrate_check_command(arguments) },
  "migrate-harness" => Command.new(:CLIRaccMigration) { |arguments| run_migrate_harness_command(arguments) },
  "reduce" => Command.new(:CLIReduce) { |arguments| run_reduce_command(arguments) },
  "samples" => Command.new(:CLISamples) { |arguments| run_samples_command(arguments) },
  "verify" => Command.new(:CLIVerify) { |arguments| run_verify_command(arguments) },
  "validate-ir" => Command.object(ValidateIRCommand.new),
  "compare" => Command.new(:CLIIRTools) { |arguments| run_compare_command(arguments) }
}.freeze
WATCH_COMMAND =

: Hash[String, Command]

Command.new(:CLIWatch) { |path| run_watch(path) }

Constants included from CLIOutputs

Ibex::CLIOutputs::WARNING_MESSAGE_IDS

Constants included from CLICounterexampleOptions

Ibex::CLICounterexampleOptions::DEFAULTS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout:, stderr:, stdin: $stdin, watch_sleeper: nil, watch_iteration_hook: nil) ⇒ CLI

Returns a new instance of CLI.



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/ibex/cli.rb', line 297

def initialize(stdout:, stderr:, stdin: $stdin, watch_sleeper: nil, watch_iteration_hook: nil)
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
  # Watch debounce is sleeper-driven; no clock is injected.
  @watch_sleeper = watch_sleeper || ->(seconds) { sleep(seconds) }
  @watch_iteration_hook = watch_iteration_hook || ->(_event, _iteration, _paths) {}
  @language = Messages.language(ENV.fetch("IBEX_LANG", nil))
  @options = {
    emit: "ruby", mode: Configuration::Registry.fetch("grammar.mode").default,
    table: Configuration::Registry.fetch("table.representation").default, line_convert: true
  }
             .merge(CLICounterexampleOptions::DEFAULTS)
  @configuration_explicit_options = {}
  @generation_grammar = nil
  @generation_automaton = @analysis_configuration = nil
end

Instance Attribute Details

#stderrObject (readonly)

: _CLIOutput



156
157
158
# File 'lib/ibex/cli.rb', line 156

def stderr
  @stderr
end

#stdoutObject (readonly)

: _CLIOutput



155
156
157
# File 'lib/ibex/cli.rb', line 155

def stdout
  @stdout
end

Class Method Details

.start(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr, watch_sleeper: nil, watch_iteration_hook: nil) ⇒ Object

rubocop:disable Layout/LineLength



288
289
290
291
292
293
294
# File 'lib/ibex/cli.rb', line 288

def self.start(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr, watch_sleeper: nil,
               watch_iteration_hook: nil)
  new(
    stdin: stdin, stdout: stdout, stderr: stderr,
    watch_sleeper: watch_sleeper, watch_iteration_hook: watch_iteration_hook
  ).run(arguments)
end

Instance Method Details

#run(arguments) ⇒ Object



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/ibex/cli.rb', line 317

def run(arguments)
  arguments = extract_language(arguments)
  @generation_grammar = nil
  @generation_automaton = @analysis_configuration = nil
  subcommand = dispatch_subcommand(arguments)
  return subcommand unless subcommand.nil?

  parser = option_parser
  remaining = parser.parse(arguments)
  validate_watch_information_options
  information = informational_result(parser)
  return information unless information.nil?

  validate_messages_options
  validate_generation_options
  path = input_path(remaining)
  validate_generation_paths!(path)
  if @options[:watch]
    run_watch_feature(path)
  else
    process_grammar(path)
  end
rescue OptionParser::ParseError, Ibex::Error, SystemCallError, SystemStackError => e
  @stderr.puts(Messages.translate("cli.error", language: @language, detail: e.message))
  1
end