|
| 1 | +# typed: true |
| 2 | + |
| 3 | +module QueryPackwerk::ConsoleHelpers |
| 4 | + extend T::Sig |
| 5 | + |
| 6 | + sig { returns(String) } |
| 7 | + def inspect |
| 8 | + 'query_packwerk console' |
| 9 | + end |
| 10 | + |
| 11 | + sig { returns(NilClass) } # returning nil is less ugly in the console. |
| 12 | + def welcome |
| 13 | + help_query_packwerk |
| 14 | + puts |
| 15 | + help_help |
| 16 | + end |
| 17 | + |
| 18 | + sig { params(type: T.nilable(T.any(String, Symbol))).returns(NilClass) } |
| 19 | + def help(type = nil) |
| 20 | + case type.to_s.downcase |
| 21 | + when 'violation' |
| 22 | + help_violation |
| 23 | + when 'violations' |
| 24 | + help_violations |
| 25 | + when 'package' |
| 26 | + help_package |
| 27 | + when 'packages' |
| 28 | + help_packages |
| 29 | + when '', 'help' |
| 30 | + help_help |
| 31 | + else |
| 32 | + puts "Unknown help topic: #{type}\n" |
| 33 | + help_help |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + sig { returns(NilClass) } |
| 38 | + def help_help |
| 39 | + puts <<~HELP |
| 40 | + Available help topics: |
| 41 | + help # This help |
| 42 | + help_violation # Help for QueryPackwerk::Violation |
| 43 | + help_violations # Help for QueryPackwerk::Violations |
| 44 | + help_package # Help for QueryPackwerk::Package |
| 45 | + help_packages # Help for QueryPackwerk::Packages |
| 46 | + HELP |
| 47 | + end |
| 48 | + |
| 49 | + sig { returns(NilClass) } |
| 50 | + def help_violation |
| 51 | + puts <<~HELP |
| 52 | + QueryPackwerk::Violation (lib/query_packwerk/violation.rb) |
| 53 | + ------------------------------------------------ |
| 54 | + .type # Returns the violation type ('privacy' or 'dependency') |
| 55 | + .class_name # Returns the violated constant name |
| 56 | + .files # Returns array of files containing the violation |
| 57 | + .producing_pack # Returns the Package that owns the violated constant |
| 58 | + .consuming_pack # Returns the Package that violated the constant |
| 59 | + .sources # Returns array of AST nodes representing the violation occurrences |
| 60 | + .sources_with_locations # Returns array of [file:line, source] pairs for each violation |
| 61 | + .source_counts # Returns hash of how often each violation source occurs |
| 62 | + .anonymous_sources # Returns array of violation sources with arguments anonymized |
| 63 | + .anonymous_sources_with_locations # Returns array of [file:line, source] pairs for each violation with arguments anonymized |
| 64 | + .count # Returns total number of violation occurrences |
| 65 | + HELP |
| 66 | + end |
| 67 | + |
| 68 | + sig { returns(NilClass) } |
| 69 | + def help_violations |
| 70 | + puts <<~HELP |
| 71 | + QueryPackwerk::Violations (lib/query_packwerk/violations.rb) |
| 72 | + -------------------------------------------------- |
| 73 | + .where(conditions) # Returns new Violations filtered by conditions |
| 74 | + .raw_sources # Returns hash of constant => AST nodes for all violations |
| 75 | + .sources # Returns hash of constant => source strings for all violations |
| 76 | + .sources_with_locations # Returns hash of constant => [file:line, source] pairs |
| 77 | + .source_counts # Returns hash of constant => {source => count} with occurrence counts |
| 78 | + .sources_with_contexts # Returns hash of constant => [file:line, source] pairs for each violation with context |
| 79 | + .anonymous_sources # Returns hash of constant => anonymized sources |
| 80 | + .anonymous_sources_with_locations # Returns array of [file:line, source] pairs for each violation with arguments anonymized |
| 81 | + .consumers(threshold) # Returns hash of consuming package names and violation counts |
| 82 | + .producers(threshold) # Returns hash of producing package names and violation counts |
| 83 | + .including_files(globs) # Returns new Violations filtered to include specific files |
| 84 | + .excluding_files(globs) # Returns new Violations filtered to exclude specific files |
| 85 | + HELP |
| 86 | + end |
| 87 | + |
| 88 | + sig { returns(NilClass) } |
| 89 | + def help_package |
| 90 | + puts <<~HELP |
| 91 | + QueryPackwerk::Package (lib/query_packwerk/package.rb) |
| 92 | + ---------------------------------------------- |
| 93 | + .name # Returns the package name |
| 94 | + .enforce_dependencies # Returns whether package enforces dependencies |
| 95 | + .enforce_privacy # Returns whether package enforces privacy |
| 96 | + .metadata # Returns the package metadata from package.yml |
| 97 | + .config # Returns the package configuration |
| 98 | + .dependencies # Returns Packages collection of dependencies |
| 99 | + .dependency_names # Returns array of dependency package names |
| 100 | + .owner # Returns the package owner or 'Unowned' |
| 101 | + .directory # Returns the package directory path |
| 102 | + .todos # Returns Violations where this package is the consumer |
| 103 | + .violations # Returns Violations where this package is the producer |
| 104 | + .consumers # Returns Packages that consume this package |
| 105 | + .consumer_names # Returns array of names of consuming packages |
| 106 | + .consumer_counts # Returns hash of consumer package names and counts |
| 107 | + HELP |
| 108 | + end |
| 109 | + |
| 110 | + sig { returns(NilClass) } |
| 111 | + def help_packages |
| 112 | + puts <<~HELP |
| 113 | + QueryPackwerk::Packages (lib/query_packwerk/packages.rb) |
| 114 | + ------------------------------------------------ |
| 115 | + .all # Returns all packages in the application |
| 116 | + .where(conditions) # Returns new Packages filtered by conditions |
| 117 | + .violations # Returns Violations for all packages in collection |
| 118 | + HELP |
| 119 | + end |
| 120 | + |
| 121 | + sig { returns(NilClass) } |
| 122 | + def help_query_packwerk |
| 123 | + puts <<~HELP |
| 124 | + QueryPackwerk (lib/query_packwerk.rb) |
| 125 | + ------------------------------ |
| 126 | + Available commands: |
| 127 | + package(pack_name) # Get a package by name |
| 128 | + Packages.all # Get all packages |
| 129 | +
|
| 130 | + Package Consumption (how others use this package): |
| 131 | + violations_for(pack_name) # Get all violations where others access this package |
| 132 | + violation_sources_for(pack_name) # Get where others access this package |
| 133 | + violation_counts_for(pack_name) # Get how often others access this package |
| 134 | + anonymous_violation_sources_for(pack_name) # Get the 'shape' of how others access this package |
| 135 | + anonymous_violation_counts_for(pack_name) # Get how often each access pattern occurs |
| 136 | + consumers(pack_name) # Get which packages consume this package |
| 137 | +
|
| 138 | + Package Dependencies (how this package uses others): |
| 139 | + todos_for(pack_name) # Get all todos where this package accesses others |
| 140 | +
|
| 141 | + Violations.all # Get all violations |
| 142 | + HELP |
| 143 | + end |
| 144 | +end |
0 commit comments