Class: Rigor::ModuleGraph::CLI::Cycles
- Inherits:
-
Object
- Object
- Rigor::ModuleGraph::CLI::Cycles
- Includes:
- EdgeFilters
- Defined in:
- lib/rigor/module_graph/cli.rb
Constant Summary
Constants included from EdgeFilters
EdgeFilters::VALID_CONFIDENCES, EdgeFilters::VALID_DIRECTIONS, EdgeFilters::VALID_EDGE_SCOPES, EdgeFilters::VALID_KINDS
Instance Method Summary collapse
-
#initialize(stdout:, stderr:, stdin:) ⇒ Cycles
constructor
A new instance of Cycles.
- #parse_options!(argv) ⇒ Object
- #run(argv) ⇒ Object
Methods included from EdgeFilters
#add_filter_options, #apply_filters, #validate!
Constructor Details
#initialize(stdout:, stderr:, stdin:) ⇒ Cycles
Returns a new instance of Cycles.
1015 1016 1017 1018 1019 1020 1021 1022 1023 |
# File 'lib/rigor/module_graph/cli.rb', line 1015 def initialize(stdout:, stderr:, stdin:) @stdout = stdout @stderr = stderr @stdin = stdin @state = { kinds: nil, confidences: nil, from: nil, depth: nil, direction: :both } end |
Instance Method Details
#parse_options!(argv) ⇒ Object
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
# File 'lib/rigor/module_graph/cli.rb', line 1057 def (argv) parser = OptionParser.new do |opts| opts. = "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 (opts, @state) opts.on("-h", "--help") do @stdout.puts opts exit 0 end end parser.parse!(argv) end |
#run(argv) ⇒ Object
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 |
# File 'lib/rigor/module_graph/cli.rb', line 1025 def run(argv) argv = argv.dup (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.}" 2 end |