Class: Insta::CLI
- Inherits:
-
Object
- Object
- Insta::CLI
- Includes:
- ANSI
- Defined in:
- lib/insta/cli.rb,
sig/insta/cli.rbs
Constant Summary collapse
- COMMANDS =
["review", "accept", "reject", "pending", "status", "clean", "help"].freeze
- MIN_GAP =
: Integer
8
Instance Method Summary collapse
-
#accept ⇒ void
: () -> void.
-
#accept_file(pending_file) ⇒ void
: (String) -> void.
-
#accept_inline_entry(entry) ⇒ void
: (Inline::pending_store_entry) -> void.
-
#clean ⇒ void
: () -> void.
-
#display_caller_context(caller_location) ⇒ void
: (String) -> void.
-
#display_diff(original, pending_file) ⇒ void
: (String, String) -> void.
-
#display_snapshot_paths(original, pending_file) ⇒ void
: (String, String) -> void.
-
#display_source_context(pending_file) ⇒ void
: (String) -> void.
-
#find_pending_files ⇒ Array[String]
: () -> Array.
-
#find_test_file(pending_file) ⇒ String?
: (String) -> String?.
-
#find_test_line(test_file, method_name) ⇒ Integer?
: (String, String) -> Integer?.
-
#header ⇒ String
: () -> String.
-
#help ⇒ void
: () -> void.
-
#help_commands ⇒ Array[[ String, String ]]
: () -> Array[[String, String]].
-
#help_environment ⇒ Array[[ String, String ]]
: () -> Array[[String, String]].
-
#help_options ⇒ Array[[ String, String ]]
: () -> Array[[String, String]].
- #highlight_lines(lines, start_line, end_line) ⇒ Array[String]
-
#initialize(args) ⇒ CLI
constructor
: (Array) -> void.
-
#pending_list ⇒ void
: () -> void.
- #pluralize(count, singular, plural = "#{singular}s") ⇒ Object
-
#print_pending_files(pending_files) ⇒ void
: (Array) -> void.
-
#print_pending_inline(inline_entries) ⇒ void
: (Array) -> void.
-
#print_review_help ⇒ void
: () -> void.
-
#print_review_summary ⇒ void
: () -> void.
-
#print_section(title, entries) ⇒ void
: (String, Array[[String, String]]) -> void.
-
#print_source_lines(file, lineno) ⇒ void
: (String, Integer) -> void.
-
#print_status_config(snapshot_path, extension) ⇒ void
: (String, String) -> void.
- #print_status_counts(snap_files, pending_files, inline_entries, directories) ⇒ void
-
#print_status_entries(entries) ⇒ void
: (Array[[String, String]]) -> void.
- #print_status_pending(pending_files, inline_entries) ⇒ void
-
#print_usage ⇒ void
: () -> void.
-
#process_inline_review_response(response, entry) ⇒ Symbol
: (String, Inline::pending_store_entry) -> Symbol.
-
#process_review_response(response, pending_file) ⇒ Symbol
: (String, String) -> Symbol.
-
#prompt_review_action ⇒ String
: () -> String.
-
#reject ⇒ void
: () -> void.
-
#reject_file(pending_file) ⇒ void
: (String) -> void.
-
#reject_inline_entry(entry) ⇒ void
: (Inline::pending_store_entry) -> void.
-
#review ⇒ void
: () -> void.
-
#review_files(files) ⇒ void
: (Array) -> void.
-
#review_inline_entries(entries) ⇒ void
: (Array) -> void.
-
#review_prompt_line ⇒ String
: () -> String.
-
#review_single_file(pending_file) ⇒ Symbol
: (String) -> Symbol.
-
#review_single_inline_entry(entry) ⇒ Symbol
: (Inline::pending_store_entry) -> Symbol.
-
#run ⇒ void
: () -> void.
-
#status ⇒ void
: () -> void.
-
#version ⇒ void
: () -> void.
Methods included from ANSI
#bold, #color?, #cyan, #dim, #green, #red, #yellow
Constructor Details
Instance Method Details
#accept ⇒ void
This method returns an undefined value.
: () -> void
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/insta/cli.rb', line 394 def accept pending_files = find_pending_files inline_entries = Inline::PendingStore.load count = pending_files.length + inline_entries.length if count.zero? puts "#{green("✓")} No pending snapshots to accept." return end pending_files.each { |file| accept_file(file) } unless inline_entries.empty? Inline::PendingStore.apply!(inline_entries) Inline::PendingStore.clean! end puts "\n#{green("✓")} Accepted #{bold(count.to_s)} #{pluralize(count, "snapshot")}." end |
#accept_file(pending_file) ⇒ void
This method returns an undefined value.
: (String) -> void
674 675 676 677 678 679 680 681 |
# File 'lib/insta/cli.rb', line 674 def accept_file(pending_file) original = pending_file.sub(/\.new\z/, "") File.rename(pending_file, original) @accepted_count = (@accepted_count || 0) + 1 puts "\n #{green("✓")} #{File.basename(original)}" end |
#accept_inline_entry(entry) ⇒ void
This method returns an undefined value.
: (Inline::pending_store_entry) -> void
371 372 373 374 375 376 377 378 379 380 |
# File 'lib/insta/cli.rb', line 371 def accept_inline_entry(entry) file = entry[:file] Inline::PendingStore.apply!([entry]) Inline::PendingStore.remove!([entry]) @accepted_count = (@accepted_count || 0) + 1 puts "\n #{green("✓")} #{File.basename(file)}:#{entry[:line]}" end |
#clean ⇒ void
This method returns an undefined value.
: () -> void
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
# File 'lib/insta/cli.rb', line 560 def clean snapshot_path = Insta.configuration.snapshot_path unless Dir.exist?(snapshot_path) puts "#{red("✗")} Snapshot directory does not exist: #{bold(snapshot_path)}" return end all_files = Dir.glob(File.join(snapshot_path, "**", "*")) pending_files = all_files.select { |file| file.end_with?(".new") } snap_files = all_files - pending_files removed = 0 pending_files.each do |file| File.delete(file) removed += 1 end inline_entries = Inline::PendingStore.load removed += inline_entries.length PendingLocations.clean! Inline::PendingStore.clean! puts "#{green("✓")} Removed #{bold(removed.to_s)} pending #{pluralize(removed, "snapshot")}." if removed.positive? puts " #{dim("#{snap_files.length} snapshot file(s) in #{snapshot_path}")}" end |
#display_caller_context(caller_location) ⇒ void
This method returns an undefined value.
: (String) -> void
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/insta/cli.rb', line 195 def display_caller_context(caller_location) file, lineno_string = caller_location.split(":", 3).first(2) return unless file && lineno_string lineno = lineno_string.to_i return unless lineno.positive? && File.exist?(file) absolute_path = File.(file) puts " #{dim("Source:")} #{cyan("#{absolute_path}:#{lineno}")}" print_source_lines(file, lineno) end |
#display_diff(original, pending_file) ⇒ void
This method returns an undefined value.
: (String, String) -> void
262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/insta/cli.rb', line 262 def display_diff(original, pending_file) if File.exist?(original) old_content = File.read(original) new_content = File.read(pending_file) extension = File.extname(original).delete_prefix(".") puts Diff.diff_with_language(old_content, new_content, file_extension: extension) else puts " #{dim("(new snapshot)")}" puts File.read(pending_file) end end |
#display_snapshot_paths(original, pending_file) ⇒ void
This method returns an undefined value.
: (String, String) -> void
209 210 211 212 |
# File 'lib/insta/cli.rb', line 209 def display_snapshot_paths(original, pending_file) puts " #{dim("Old:")} #{dim(original)}" puts " #{dim("New:")} #{dim(pending_file)}" end |
#display_source_context(pending_file) ⇒ void
This method returns an undefined value.
: (String) -> void
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/insta/cli.rb', line 141 def display_source_context(pending_file) locations = @pending_locations || {} caller_location = locations[pending_file] if caller_location display_caller_context(caller_location) else snapshot = Snapshot.parse(File.read(pending_file)) source = snapshot.source puts " #{dim("Source:")} #{cyan(source)}" if source test_file = find_test_file(pending_file) return unless test_file method_name = source&.split("#")&.last lineno = method_name ? find_test_line(test_file, method_name) : nil location = lineno ? "#{test_file}:#{lineno}" : test_file puts " #{dim("Test:")} #{cyan(location)}" print_source_lines(test_file, lineno) if lineno end end |
#find_pending_files ⇒ Array[String]
: () -> Array
667 668 669 670 671 |
# File 'lib/insta/cli.rb', line 667 def find_pending_files snapshot_path = Insta.configuration.snapshot_path Dir.glob(File.join(snapshot_path, "**", "*.new")) end |
#find_test_file(pending_file) ⇒ String?
: (String) -> String?
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/insta/cli.rb', line 166 def find_test_file(pending_file) snapshot_path = Insta.configuration.snapshot_path relative = pending_file.sub(%r{\A#{Regexp.escape(snapshot_path)}/}, "") test_dir = File.dirname(relative) test_file = File.join("test", "#{test_dir}.rb") return test_file if File.exist?(test_file) nil end |
#find_test_line(test_file, method_name) ⇒ Integer?
: (String, String) -> Integer?
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/insta/cli.rb', line 178 def find_test_line(test_file, method_name) lines = File.readlines(test_file) lines.each_with_index do |line, i| return i + 1 if line.match?(/\bdef\s+#{Regexp.escape(method_name)}\b/) end description = method_name.sub(/\Atest_\d+_/, "").tr("_", " ") lines.each_with_index do |line, i| return i + 1 if line.include?("test \"#{description}\"") || line.include?("test '#{description}'") end nil end |
#header ⇒ String
: () -> String
628 629 630 |
# File 'lib/insta/cli.rb', line 628 def header "#{bold("insta")} v#{Insta::VERSION} #{dim("📸 Snapshot Testing for Ruby")}" end |
#help ⇒ void
This method returns an undefined value.
: () -> void
589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# File 'lib/insta/cli.rb', line 589 def help puts header puts puts dim("Description:") puts " Snapshot tests assert values against a reference value. Think of it as" puts " a supercharged version of #{cyan("assert_equal")} where the reference value is" puts " managed by #{bold("insta")} for you." puts print_usage print_section("Commands:", help_commands) print_section("Options:", ) print_section("Environment:", help_environment) end |
#help_commands ⇒ Array[[ String, String ]]
: () -> Array[[String, String]]
638 639 640 641 642 643 644 645 646 647 648 |
# File 'lib/insta/cli.rb', line 638 def help_commands [ ["review", "Interactive review of pending snapshots"], ["accept", "Accept all pending snapshots"], ["reject", "Reject all pending snapshots"], ["pending", "List pending snapshots"], ["status", "Show snapshot overview and pending files"], ["clean", "Remove pending snapshot files"], ["help", "Display usage information"] ] end |
#help_environment ⇒ Array[[ String, String ]]
: () -> Array[[String, String]]
659 660 661 662 663 664 |
# File 'lib/insta/cli.rb', line 659 def help_environment [ ["INSTA_UPDATE=<mode>", "Set update mode #{dim("[auto|always|new|no]")}"], ["INSTA_FORCE_PASS=1", "Create .snap.new without failing tests"] ] end |
#help_options ⇒ Array[[ String, String ]]
: () -> Array[[String, String]]
651 652 653 654 655 656 |
# File 'lib/insta/cli.rb', line 651 def [ ["-h, --help", "Display usage information"], ["-v, --version", "Display version information"] ] end |
#highlight_lines(lines, start_line, end_line) ⇒ Array[String]
254 255 256 257 258 259 |
# File 'lib/insta/cli.rb', line 254 def highlight_lines(lines, start_line, end_line) snippet = lines[start_line..end_line] || [] code = snippet.join SyntaxHighlight.highlight(code, colorable: color?).lines end |
#pending_list ⇒ void
This method returns an undefined value.
: () -> void
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/insta/cli.rb', line 432 def pending_list pending_files = find_pending_files inline_entries = Inline::PendingStore.load if pending_files.empty? && inline_entries.empty? puts "#{green("✓")} No pending snapshots." return end total = pending_files.length + inline_entries.length puts "#{yellow("●")} Pending snapshots #{dim("(#{total})")}:\n\n" print_pending_files(pending_files) unless pending_files.empty? return if inline_entries.empty? puts unless pending_files.empty? print_pending_inline(inline_entries) end |
#pluralize(count, singular, plural = "#{singular}s") ⇒ Object
45 |
# File 'lib/insta/cli.rb', line 45 def pluralize(count, singular, plural = "#{singular}s") = count == 1 ? singular : plural |
#print_pending_files(pending_files) ⇒ void
This method returns an undefined value.
: (Array) -> void
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/insta/cli.rb', line 453 def print_pending_files(pending_files) locations = PendingLocations.load pending_files.each do |pending_file| caller_location = locations[pending_file] if caller_location file, lineno = caller_location.split(":", 3).first(2) absolute_path = file ? File.(file) : nil location = absolute_path ? "#{absolute_path}:#{lineno}" : caller_location puts " #{yellow("›")} #{pending_file}" puts " #{dim("at")} #{cyan(location)}" else puts " #{yellow("›")} #{pending_file}" end end end |
#print_pending_inline(inline_entries) ⇒ void
This method returns an undefined value.
: (Array) -> void
473 474 475 476 477 478 479 480 481 482 |
# File 'lib/insta/cli.rb', line 473 def print_pending_inline(inline_entries) inline_entries.each do |entry| file = entry[:file] line = entry[:line] absolute_path = File.(file) puts " #{yellow("›")} #{dim("inline")} #{File.basename(file)}:#{line}" puts " #{dim("at")} #{cyan("#{absolute_path}:#{line}")}" end end |
#print_review_help ⇒ void
This method returns an undefined value.
: () -> void
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/insta/cli.rb', line 215 def print_review_help extension = Insta.configuration.snapshot_extension puts puts " #{bold(green("a"))} #{bold(green("accept"))} " \ "#{dim("Apply the new snapshot as the current #{extension} file")}" puts " #{bold(red("r"))} #{bold(red("reject"))} " \ "#{dim("Discard the #{extension}.new file and keep the current snapshot")}" puts " #{dim("s")} #{dim("skip")} " \ "#{dim("Skip this snapshot and continue reviewing")}" puts " #{bold(green("A"))} #{bold(green("accept all"))} " \ "#{dim("Accept this and all remaining pending snapshots")}" puts " #{bold(red("R"))} #{bold(red("reject all"))} " \ "#{dim("Reject this and all remaining pending snapshots")}" puts " #{dim("q")} #{dim("quit")} " \ "#{dim("Stop reviewing and exit")}" puts end |
#print_review_summary ⇒ void
This method returns an undefined value.
: () -> void
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
# File 'lib/insta/cli.rb', line 693 def print_review_summary parts = [] #: Array[String] parts << green("#{@accepted_count} accepted") if @accepted_count.positive? parts << red("#{@rejected_count} rejected") if @rejected_count.positive? remaining_files = find_pending_files remaining_inline = Inline::PendingStore.load remaining_count = remaining_files.length + remaining_inline.length parts << yellow("#{remaining_count} skipped") if remaining_count.positive? summary = parts.any? ? " #{dim("(")}#{parts.join(dim(", "))}#{dim(")")}" : "" puts if remaining_count.zero? puts "#{green("✓")} Review complete.#{summary}" else puts "#{green("✓")} Review complete.#{summary}" puts "\n #{cyan("bundle exec insta review")}\n\n" end end |
#print_section(title, entries) ⇒ void
This method returns an undefined value.
: (String, Array[[String, String]]) -> void
612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/insta/cli.rb', line 612 def print_section(title, entries) puts dim(title) max_label = entries.map { |label, _| label.length }.max || 0 entries.each do |label, description| dot_count = MIN_GAP + (max_label - label.length) dots = dim("·" * dot_count) puts " #{cyan(label)} #{dots} #{description}" end puts end |
#print_source_lines(file, lineno) ⇒ void
This method returns an undefined value.
: (String, Integer) -> void
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/insta/cli.rb', line 235 def print_source_lines(file, lineno) lines = File.readlines(file) start_line = [lineno - 3, 0].max end_line = [lineno + 1, lines.length - 1].min highlighted = highlight_lines(lines, start_line, end_line) puts (start_line..end_line).each do |i| line_num = i + 1 prefix = line_num == lineno ? cyan("→ ") : " " puts " #{prefix}#{dim(format("%4d", line_num))} #{highlighted[i - start_line]}" end puts end |
#print_status_config(snapshot_path, extension) ⇒ void
This method returns an undefined value.
: (String, String) -> void
507 508 509 510 511 |
# File 'lib/insta/cli.rb', line 507 def print_status_config(snapshot_path, extension) config_entries = [["Snapshot path", snapshot_path], ["Extension", extension]] #: Array[[String, String]] print_status_entries(config_entries) puts end |
#print_status_counts(snap_files, pending_files, inline_entries, directories) ⇒ void
514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/insta/cli.rb', line 514 def print_status_counts(snap_files, pending_files, inline_entries, directories) print_status_entries( [ ["Snapshots", snap_files.length.to_s], ["Pending files", pending_files.empty? ? "0" : yellow(pending_files.length.to_s)], ["Pending inline", inline_entries.empty? ? "0" : yellow(inline_entries.length.to_s)], ["Directories", directories.length.to_s] ] ) puts end |
#print_status_entries(entries) ⇒ void
This method returns an undefined value.
: (Array[[String, String]]) -> void
549 550 551 552 553 554 555 556 557 |
# File 'lib/insta/cli.rb', line 549 def print_status_entries(entries) max_label = entries.map { |label, _| label.length }.max || 0 entries.each do |label, value| dot_count = MIN_GAP + (max_label - label.length) dots = dim("·" * dot_count) puts " #{cyan(label)} #{dots} #{value}" end end |
#print_status_pending(pending_files, inline_entries) ⇒ void
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
# File 'lib/insta/cli.rb', line 527 def print_status_pending(pending_files, inline_entries) if pending_files.empty? && inline_entries.empty? puts "#{green("✓")} No pending snapshots." return end unless pending_files.empty? puts "Pending file snapshots:\n\n" pending_files.each { |file| puts " #{yellow("›")} #{file}" } puts end unless inline_entries.empty? puts "Pending inline snapshots:\n\n" inline_entries.each { |entry| puts " #{yellow("›")} #{entry[:file]}:#{entry[:line]}" } puts end puts " #{cyan("bundle exec insta review")}\n" end |
#print_usage ⇒ void
This method returns an undefined value.
: () -> void
605 606 607 608 609 |
# File 'lib/insta/cli.rb', line 605 def print_usage puts dim("Usage:") puts " insta #{dim("<command>")} #{dim("[options]")}" puts end |
#process_inline_review_response(response, entry) ⇒ Symbol
: (String, Inline::pending_store_entry) -> Symbol
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/insta/cli.rb', line 348 def process_inline_review_response(response, entry) case response when "a" accept_inline_entry(entry) :continue when "r" reject_inline_entry(entry) :continue when "accept all" accept_inline_entry(entry) :accept_all when "reject all" reject_inline_entry(entry) :reject_all when "q" :quit else puts " #{dim("Skipped.")}\n\n" :continue end end |
#process_review_response(response, pending_file) ⇒ Symbol
: (String, String) -> Symbol
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/insta/cli.rb', line 276 def process_review_response(response, pending_file) case response when "a" accept_file(pending_file) :continue when "r" reject_file(pending_file) :continue when "accept all" accept_file(pending_file) :accept_all when "reject all" reject_file(pending_file) :reject_all when "q" :quit else puts " #{dim("Skipped.")}\n\n" :continue end end |
#prompt_review_action ⇒ String
: () -> String
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/insta/cli.rb', line 118 def prompt_review_action puts print review_prompt_line response = $stdin.gets&.strip || "s" if response.downcase == "h" print_review_help print review_prompt_line response = $stdin.gets&.strip || "s" end response.downcase end |
#reject ⇒ void
This method returns an undefined value.
: () -> void
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/insta/cli.rb', line 415 def reject pending_files = find_pending_files inline_entries = Inline::PendingStore.load count = pending_files.length + inline_entries.length if count.zero? puts "#{green("✓")} No pending snapshots to reject." return end pending_files.each { |file| reject_file(file) } Inline::PendingStore.clean! unless inline_entries.empty? puts "\n#{green("✓")} Rejected #{bold(count.to_s)} #{pluralize(count, "snapshot")}." end |
#reject_file(pending_file) ⇒ void
This method returns an undefined value.
: (String) -> void
684 685 686 687 688 689 690 |
# File 'lib/insta/cli.rb', line 684 def reject_file(pending_file) File.delete(pending_file) @rejected_count = (@rejected_count || 0) + 1 puts "\n #{red("✗")} #{File.basename(pending_file)}" end |
#reject_inline_entry(entry) ⇒ void
This method returns an undefined value.
: (Inline::pending_store_entry) -> void
383 384 385 386 387 388 389 390 391 |
# File 'lib/insta/cli.rb', line 383 def reject_inline_entry(entry) file = entry[:file] Inline::PendingStore.remove!([entry]) @rejected_count = (@rejected_count || 0) + 1 puts "\n #{red("✗")} #{File.basename(file)}:#{entry[:line]}" end |
#review ⇒ void
This method returns an undefined value.
: () -> void
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/insta/cli.rb', line 48 def review pending_files = find_pending_files inline_entries = Inline::PendingStore.load if pending_files.empty? && inline_entries.empty? puts "#{green("✓")} No pending snapshots to review." return end @pending_locations = PendingLocations.load @accepted_count = 0 @rejected_count = 0 total = pending_files.length + inline_entries.length puts "#{yellow("●")} Found #{bold(total.to_s)} pending #{pluralize(total, "snapshot")} to review.\n\n" @quit = false review_files(pending_files) unless pending_files.empty? review_inline_entries(inline_entries) unless @quit || inline_entries.empty? print_review_summary end |
#review_files(files) ⇒ void
This method returns an undefined value.
: (Array) -> void
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/insta/cli.rb', line 72 def review_files(files) accept_all = false reject_all = false files.each do |pending_file| if accept_all accept_file(pending_file) next end if reject_all reject_file(pending_file) next end result = review_single_file(pending_file) case result when :accept_all accept_all = true when :reject_all reject_all = true when :quit puts "Quit." @quit = true break end end end |
#review_inline_entries(entries) ⇒ void
This method returns an undefined value.
: (Array) -> void
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/insta/cli.rb', line 299 def review_inline_entries(entries) accept_all = false reject_all = false entries.each do |entry| if accept_all accept_inline_entry(entry) next end if reject_all reject_inline_entry(entry) next end result = review_single_inline_entry(entry) case result when :accept_all accept_all = true when :reject_all reject_all = true when :quit puts "Quit." break end end end |
#review_prompt_line ⇒ String
: () -> String
134 135 136 137 138 |
# File 'lib/insta/cli.rb', line 134 def review_prompt_line " #{bold(green("[a]ccept"))} #{bold(red("[r]eject"))} #{dim("[s]kip")} " \ "#{bold(green("[A]ccept all"))} #{bold(red("[R]eject all"))} " \ "#{dim("[q]uit")} #{dim("[h]elp")}: " end |
#review_single_file(pending_file) ⇒ Symbol
: (String) -> Symbol
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/insta/cli.rb', line 103 def review_single_file(pending_file) original = pending_file.sub(/\.new\z/, "") snap_name = File.basename(original) puts bold("─── #{snap_name} ───") display_source_context(pending_file) display_snapshot_paths(original, pending_file) puts display_diff(original, pending_file) response = prompt_review_action process_review_response(response, pending_file) end |
#review_single_inline_entry(entry) ⇒ Symbol
: (Inline::pending_store_entry) -> Symbol
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/insta/cli.rb', line 329 def review_single_inline_entry(entry) file = entry[:file] line = entry[:line] puts bold("─── inline snapshot ───") puts " #{dim("Source:")} #{cyan("#{File.(file)}:#{line}")}" print_source_lines(file, line) if File.exist?(file) old_content = entry[:old_content] || "" new_content = entry[:content] || "" puts Diff.diff(old_content, new_content) response = prompt_review_action process_inline_review_response(response, entry) end |
#run ⇒ void
This method returns an undefined value.
: () -> void
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/insta/cli.rb', line 21 def run ConfigManifest.apply! case @command when "review" then review when "accept" then accept when "reject" then reject when "pending" then pending_list when "status" then status when "clean" then clean when "help", "--help", "-h" then help when "--version", "-v" then version else warn header warn warn "#{dim("Invalid command:")} #{red(@command)}" warn warn "Run #{cyan("insta help")} for usage information." exit 1 end end |
#status ⇒ void
This method returns an undefined value.
: () -> void
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/insta/cli.rb', line 485 def status snapshot_path = Insta.configuration.snapshot_path extension = Insta.configuration.snapshot_extension puts header puts all_entries = Dir.exist?(snapshot_path) ? Dir.glob(File.join(snapshot_path, "**", "*")) : [] #: Array[String] pending_extension = "#{extension}.new" snap_files = all_entries.select { |file| File.file?(file) && file.end_with?(extension) && !file.end_with?(pending_extension) } pending_files = all_entries.select { |file| File.file?(file) && file.end_with?(pending_extension) } inline_entries = Inline::PendingStore.load directories = all_entries.select { |file| File.directory?(file) } print_status_config(snapshot_path, extension) print_status_counts(snap_files, pending_files, inline_entries, directories) print_status_pending(pending_files, inline_entries) end |
#version ⇒ void
This method returns an undefined value.
: () -> void
633 634 635 |
# File 'lib/insta/cli.rb', line 633 def version puts header end |