Class: Rigor::CLI::AnnotateCommand
- Inherits:
-
Object
- Object
- Rigor::CLI::AnnotateCommand
- Defined in:
- lib/rigor/cli/annotate_command.rb
Overview
Executes ‘rigor annotate FILE`.
For every source line the command finds the expression the line evaluates to — the last statement that ends on the line (so ‘1; 2; 3` reports `3`), or, for a line that no statement closes, the widest expression ending there (so the `if nil` header reports its condition). It infers that expression’s type and appends a ‘#=> dump_type: <type>` comment.
The annotated source is re-parsed with Prism — a sanity gate, since the appended text is always a comment — and printed to stdout with IRB-style syntax highlighting via PrismColorizer.
Constant Summary collapse
- USAGE =
"Usage: rigor annotate [options] FILE"- ANNOTATION_PATTERN =
Appended ‘ #=> dump_type: <type>` suffix. Matched and stripped before re-annotating so re-running is idempotent.
/\s*#=>\s*dump_type:.*\z/
Instance Method Summary collapse
-
#initialize(argv:, out:, err:) ⇒ AnnotateCommand
constructor
A new instance of AnnotateCommand.
-
#run ⇒ Integer
CLI exit status.
Constructor Details
#initialize(argv:, out:, err:) ⇒ AnnotateCommand
Returns a new instance of AnnotateCommand.
34 35 36 37 38 |
# File 'lib/rigor/cli/annotate_command.rb', line 34 def initialize(argv:, out:, err:) @argv = argv @out = out @err = err end |
Instance Method Details
#run ⇒ Integer
Returns CLI exit status.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rigor/cli/annotate_command.rb', line 41 def run = file = @argv.shift if file.nil? @err.puts(USAGE) return CLI::EXIT_USAGE end unless File.file?(file) @err.puts("annotate: file not found: #{file}") return 1 end execute(file, ) end |