class Rigor::ModuleGraph::CLI::Cycles
Public Class Methods
Source
# File lib/rigor/module_graph/cli.rb, line 1059 def initialize(stdout:, stderr:, stdin:) @stdout = stdout @stderr = stderr @stdin = stdin @state = { kinds: nil, confidences: nil, from: nil, depth: nil, direction: :both } end
Public Instance Methods
Source
# File lib/rigor/module_graph/cli.rb, line 1101 def parse_options!(argv) parser = OptionParser.new do |opts| opts.banner = "Usage: rigor-module-graph cycles [options] [FILE]" # `--only` kept as an alias for `--kind` for backward # compat with the Phase 1 flag. opts.on("--only KINDS", Array, "Alias for --kind") do |kinds| @state[:kinds] = kinds end add_filter_options(opts, @state) opts.on("-h", "--help") do @stdout.puts opts exit 0 end end parser.parse!(argv) end
Source
# File lib/rigor/module_graph/cli.rb, line 1069 def run(argv) argv = argv.dup parse_options!(argv) path, = argv io = path ? File.open(path, "r") : @stdin begin edges = EdgeIO.read(io) ensure io.close if path && !io.closed? end edges = apply_filters( edges, kinds: @state[:kinds], confidences: @state[:confidences], from: @state[:from], depth: @state[:depth], direction: @state[:direction], edge_scope: @state[:edge_scope] ) cycles = CycleDetector.detect(edges) if cycles.empty? @stderr.puts "rigor-module-graph cycles: no cycles found" 0 else cycles.each { |c| @stdout.puts c.to_s } 1 end rescue OptionParser::ParseError => e @stderr.puts "rigor-module-graph cycles: #{e.message}" 2 end