Module: Rigor::CLI::Options
- Defined in:
- lib/rigor/cli/options.rb
Overview
Shared option plumbing for the subcommands.
Today it owns the editor-mode surface that rigor check and rigor type-of both expose: the --tmp-file /
--instead-of flag pair and the buffer-binding resolution that validates it. That resolution used to be copied
verbatim into both Rigor::CLI and TypeOfCommand, so a fix to one (the paired-flag check, the readability
check, the error wording) could silently miss the other. Centralising it keeps the two editor-mode entry points in
lockstep.
Class Method Summary collapse
-
.add_config(parser, options) ⇒ Object
Defines the standard
--config=PATHflag onparser, writing the path intooptions[:config]. -
.add_editor_mode(parser, options) ⇒ Object
Defines the
--tmp-file/--instead-ofeditor-mode flag pair onparser, writing intooptions. -
.resolve_buffer_binding(options, err:) ⇒ Object
Resolves the editor-mode buffer binding from parsed
options: returns nil when neither editor-mode flag is set, aAnalysis::BufferBindingwhen the pair is valid, or:usage_error(after writing the reason toerr) when the flags are unpaired or the temp file is unreadable.
Class Method Details
.add_config(parser, options) ⇒ Object
Defines the standard --config=PATH flag on parser, writing the path into options[:config]. Used by every
subcommand that loads a .rigor.yml; the few whose --config help text is intentionally bespoke (diff,
mcp, show-bleedingedge) keep their own parser.on rather than this shared wording.
20 21 22 |
# File 'lib/rigor/cli/options.rb', line 20 def add_config(parser, ) parser.on("--config=PATH", "Path to the Rigor configuration file") { |value| [:config] = value } end |
.add_editor_mode(parser, options) ⇒ Object
Defines the --tmp-file / --instead-of editor-mode flag pair on parser, writing into options.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rigor/cli/options.rb', line 25 def add_editor_mode(parser, ) parser.on("--tmp-file=PATH", "Editor mode: read source bytes from PATH instead of --instead-of (paired)") do |value| [:tmp_file] = value end parser.on("--instead-of=PATH", "Editor mode: the logical project path the buffer represents (paired with --tmp-file)") do |value| [:instead_of] = value end end |
.resolve_buffer_binding(options, err:) ⇒ Object
Resolves the editor-mode buffer binding from parsed options: returns nil when neither editor-mode flag is set,
a Analysis::BufferBinding when the pair is valid, or :usage_error (after writing the reason to err) when
the flags are unpaired or the temp file is unreadable.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rigor/cli/options.rb', line 39 def resolve_buffer_binding(, err:) tmp = [:tmp_file] instead = [:instead_of] return nil if tmp.nil? && instead.nil? if tmp.nil? || instead.nil? err.puts("--tmp-file and --instead-of must appear together") return :usage_error end unless File.file?(tmp) err.puts("--tmp-file #{tmp.inspect}: no such file or not readable") return :usage_error end Analysis::BufferBinding.new(logical_path: instead, physical_path: tmp) end |