Class: Pinspec::CLI
- Inherits:
-
Thor
- Object
- Thor
- Pinspec::CLI
- Defined in:
- lib/pinspec/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #analyze(app_path = ".") ⇒ Object
- #capture(target) ⇒ Object
- #pin(target) ⇒ Object
- #plan(target) ⇒ Object
- #report ⇒ Object
- #validate(target) ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
7 8 9 |
# File 'lib/pinspec/cli.rb', line 7 def self.exit_on_failure? true end |
Instance Method Details
#analyze(app_path = ".") ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pinspec/cli.rb', line 46 def analyze(app_path = ".") guarded do profile = Analyzer::AppProfileReader.read(app_path) print_app(profile) puts print_schema(profile.schema) puts print_factories(profile.factories) print_warnings(profile) end end |
#capture(target) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/pinspec/cli.rb', line 72 def capture(target) guarded do file, method = Analyzer::TargetParser.split_target(target) result = Runner::Capture.new( app_root: [:app], target: file, method: method, max_cases: [:cases], boots: [:boots], compare_sql: [:"compare-sql"], sandbox_env: app_env, sample: [:sample], redact: ![:"no-redact"] ).run print_capture(result) raise NothingStableToPin, (result.stability) if result.stability.nothing_to_pin? end end |
#pin(target) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/pinspec/cli.rb', line 110 def pin(target) guarded do refuse_unbuilt_backend! warn_about_redaction! file, method = Analyzer::TargetParser.split_target(target) capture = Runner::Capture.new( app_root: [:app], target: file, method: method, max_cases: [:cases], boots: [:boots], sandbox_env: app_env, sample: [:sample], redact: ![:"no-redact"] ).run print_capture(capture) raise NothingStableToPin, (capture.stability) if capture.stability.nothing_to_pin? written = Emit::SpecWriter.new( app_root: [:app], target: capture.target, plan: capture.plan, corpus: capture.corpus, stability: capture.stability, fk_map: Analyzer::AppProfileReader.read([:app]).schema.fk_map, force: [:force] ).write! puts print_written(written) return if [:"skip-verify"] outcomes = Verify::Verifier.new( app_root: [:app], spec_path: written.spec_path, level: [:"verify-level"].to_sym, env: app_env, captured_tz: capture.plan.env_fingerprint[:tz] ).verify puts print_verification(outcomes) report_path = Report::Summary.new( app_root: [:app], profile: Analyzer::AppProfileReader.read([:app]), target: capture.target, plan: capture.plan, corpus: capture.corpus, stability: capture.stability, written: written, outcomes: outcomes ).write! puts row "report", report_path raise VerifyFailed, (outcomes) unless outcomes.all?(&:green?) end end |
#plan(target) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pinspec/cli.rb', line 22 def plan(target) guarded do file, method = Analyzer::TargetParser.split_target(target) target_profile = Analyzer::TargetParser.parse(file, method) print_profile(target_profile) puts app_profile = Analyzer::AppProfileReader.read([:app]) setup_plan = Setup::ContextBuilder.build(target: target_profile, profile: app_profile) corpus = Inputs::Corpus.build( target: target_profile, plan: setup_plan, schema: app_profile.schema, max_cases: [:cases] ) print_plan(setup_plan) puts print_corpus(corpus) end end |
#report ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/pinspec/cli.rb', line 201 def report guarded do path = File.join([:app], Report::Summary::OUTPUT) unless File.file?(path) raise TargetNotFound, "no report at #{path}. Run `pinspec pin` first (or `pinspec validate`, " \ "which adds the mutation scores); either writes one every time." end puts Analyzer::Source.read(path) end end |
#validate(target) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/pinspec/cli.rb', line 166 def validate(target) guarded do file, method = Analyzer::TargetParser.split_target(target) capture = Runner::Capture.new( app_root: [:app], target: file, method: method, max_cases: [:cases], sandbox_env: app_env ).run raise NothingStableToPin, (capture.stability) if capture.stability.nothing_to_pin? profile = Analyzer::AppProfileReader.read([:app]) report = Validate::PinScorer.new( app_root: [:app], target: capture.target, plan: capture.plan, corpus: capture.corpus, stability: capture.stability, fk_map: profile.schema.fk_map, env: app_env, test_command: [:"test-command"] ).run print_scores(report) summary = Report::Summary.new( app_root: [:app], profile: profile, target: capture.target, plan: capture.plan, corpus: capture.corpus, stability: capture.stability, scores: report ) puts puts " report #{summary.write!}" end end |
#version ⇒ Object
12 13 14 15 |
# File 'lib/pinspec/cli.rb', line 12 def version puts "pinspec #{Pinspec::VERSION} " \ "(probe v#{Pinspec::PROBE_VERSION}, serializer v#{Pinspec::SERIALIZER_VERSION})" end |