Class: PgVerify::Cli::BaseCommand
- Inherits:
-
Thor
- Object
- Thor
- PgVerify::Cli::BaseCommand
- Defined in:
- lib/pg-verify/cli/cli.rb
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Make Thor exit with non-0 in case of errors.
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
Make Thor exit with non-0 in case of errors
300 |
# File 'lib/pg-verify/cli/cli.rb', line 300 def self.exit_on_failure?(); true end |
Instance Method Details
#dcca ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/pg-verify/cli/cli.rb', line 169 def dcca() models = CliUtils.load_models() models.each { |model| Shell::LoadingPrompt.while_loading("Checking for deadlocks") { NuSMV::Runner.new().run_check!(model); "ok" } dcca = Model::DCCA.new(model, NuSMV::Runner.new) result = Shell::LoadingPrompt.while_loading("Calculating DCCA for #{model.name.to_s.c_string}") { dcca.perform() } result.each { |hazard, crit_sets| s = crit_sets.length == 1 ? "" : "s" = "Hazard #{hazard.text.to_s.c_string} (#{hazard.expression.to_s.c_blue}) " += "has #{crit_sets.length.to_s.c_num} minimal critical fault set#{s}:" if crit_sets.length > 0 += "has no minimal critical fault sets, meaning it is safe!".c_success if crit_sets.length == 0 puts crit_sets.each { |set| puts "\t{ #{set.map(&:to_s).map(&:c_blue).join(', ')} }" } } } end |
#doctor ⇒ Object
292 293 294 |
# File 'lib/pg-verify/cli/cli.rb', line 292 def doctor() Doctor.check() end |
#init ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/pg-verify/cli/cli.rb', line 253 def init() target = [:directory].blank? ? Dir.pwd() : File.([:directory]) if Dir.exist?(target) && Dir.entries(target).size > 2 puts "The target directory #{target.c_file} isn't empty!" exit 1 end # Create target dir FileUtils.mkdir_p(target) # Copy files to target template_dir = File.join(PgVerify.root, "data", "project-template") files = Dir.glob(File.join(template_dir, '**', '*'), File::FNM_DOTMATCH).select { |f| File.file?(f) } files.each { |f| target_file = File.join(target, f.sub(template_dir, "")) target_file = target_file.gsub(".resource", "") FileUtils.mkdir_p(File.dirname(target_file)) FileUtils.cp(f, target_file) unless File.basename(f) == ".keep" } # Copy the actual default config into the project as that # will contain all keys and should be commented FileUtils.cp(File.join(PgVerify.root, "data", "config", "pg-verify.yml"), File.join(target, ".pg-verify.yml")) prelude_pg_file = File.join(PgVerify.root, "integration_tests", "ruby_dsl", "016_pressure_tank.rb") FileUtils.cp(prelude_pg_file, File.join(target, Settings.ruby_dsl.default_script_name)) # Initialize git project Dir.chdir(target) { Core::CMDRunner.run_cmd("git init") Core::CMDRunner.run_cmd("git add .") Core::CMDRunner.run_cmd("git commit -m \"Initial Commit\"") } puts "Successfully initialized project at #{target.c_file}!" puts "You can read the #{'README.md'.c_file} to get started." puts "Run #{'pg-verify doctor'.c_blue} and follow the instructions to set up your environment!" end |
#simulate ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/pg-verify/cli/cli.rb', line 207 def simulate() = { render_labels: ![:"hide-labels"], render_precons: ![:"hide-precons"], render_guards: ![:"hide-guards"], render_actions: ![:"hide-actions"] } models = CliUtils.load_models() runner = NuSMV::Runner.new models.each { |model| Shell::LoadingPrompt.while_loading("Checking for deadlocks") { NuSMV::Runner.new().run_check!(model); "ok" } trace = Shell::LoadingPrompt.while_loading("Simulating model #{model.name.to_s.c_string}") { runner.run_simulation(model, [:steps], random: [:random]) } # Print the trace puts trace.to_s next unless [:png] # Prepare output dir out_dir = File.("simulate-" + model.name.to_s.gsub(/\W+/, '_').downcase, Settings.outdir) FileUtils.mkdir_p(out_dir) # Generate images Shell::LoadingPrompt.while_loading("Rendering states") { |printer| trace.states.each_with_index { |variable_state, index| printer.printl("Step #{index + 1}/#{trace.states.length}") puml = Transform::PumlTransformation.new().transform_graph(model, variable_state: variable_state) png = PlantumlBuilder::Formats::PNG.new(puml).load out_path = File.("step-#{index}.png", out_dir) File.binwrite(out_path, png) } } puts "Wrote #{trace.states.length.to_s.c_num} files to #{out_dir.c_file}" } end |
#test ⇒ Object
140 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/pg-verify/cli/cli.rb', line 140 def test() models = CliUtils.load_models() models.each { |model| Shell::LoadingPrompt.while_loading("Checking for deadlocks") { NuSMV::Runner.new().run_check!(model); "ok" } results = Shell::LoadingPrompt.while_loading("Running specifications") { NuSMV::Runner.new().run_specs(model) } results.each { |result| stat_string = result.success ? "PASSED".c_success : "FAILED".c_error puts "[ #{stat_string} ] #{result.spec.text}" puts " #{result.spec.expression.to_s.c_blue}" unless result.success puts " Here is a counter example:".c_red trace_s = result.trace.to_s.indented(str: " >> ".c_red) puts trace_s + "\n" end } } end |
#version ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/pg-verify/cli/cli.rb', line 125 def version() = File.read(File.join(PgVerify.root, "data", "banner.txt")) = .gsub("0.1.0", PgVerify::VERSION) colors = [ "red", "orange", "yellow", "orange", "red" ] = .split("\n").each_with_index.map { |l, i| l.send(:"c_#{colors[i]}") }.join("\n") puts puts puts "You are running #{'pg-verify'.c_string} version #{PgVerify::VERSION.to_s.c_num}" puts "Installation root: #{PgVerify.root.to_s.c_file}" end |