module Bait::CLI
Constants
- USAGE
Public Class Methods
init()
click to toggle source
Create .bait/ and config.yml and example .bait/test.sh I do not seek to read your mind, instead I’d prefer that you contribute Scripts for different Contexts/Technologies
# File lib/bait/cli.rb, line 26 def self.init bait_dir = File.join(Dir.pwd, ".bait") if File.directory? bait_dir puts "Directory already exists: #{bait_dir}" else script = File.join(bait_dir, 'test.sh') FileUtils.mkdir bait_dir puts "Created #{bait_dir}" File.open(script, 'w') do |f| f.puts "#!/bin/bash" f.puts "echo 'Running tests. Oh no tests.'" f.puts "echo 0 examples, 1 failure" f.puts "exit 1" end File.chmod(0744, script) puts "Created executable script #{script}." name = File.basename(script) config_file = File.join(bait_dir, 'config.yml') File.open(config_file, "w") do |f| f.puts "---" f.puts "- #{name}" end puts "Setup one phase in #{config_file} pointing to #{name}." end end
method_missing(method)
click to toggle source
# File lib/bait/cli.rb, line 98 def self.method_missing method unless method.to_sym == :help puts "Command not found: #{method}" end puts USAGE end
server(username=false, password=false)
click to toggle source
Start the server
# File lib/bait/cli.rb, line 13 def self.server username=false, password=false puts "** Bait/#{Bait::VERSION} booting up in #{Bait.env} environment" if Bait.env == "production" && Bait.assets.missing? Bait.assets.compile! end require 'bait/api' Bait::Api.run! end
test(name=nil)
click to toggle source
Run a defined phase
# File lib/bait/cli.rb, line 54 def self.test name=nil dir = Dir.pwd, ".bait" config_file = File.join(dir, "config.yml") if File.exists? config_file require 'yaml' scripts = YAML.load_file(config_file) if scripts.empty? puts "Define your scripts in #{config_file}" exit 1 end runscript = proc do |script, quit| puts "Running #{script}" system script status = $?.exitstatus puts "Exited with status #{status}" exit status if quit end if name script = File.join(dir, name) scripts.select do |a| if a == name unless File.executable? script puts "Missing executable #{script}" exit 1 else runscript.call(script) end end end puts "Script #{script} not defined in #{config_file}" exit 1 else puts "Running all defined in #{config_file}" scripts.each do |name| script = File.join(dir, name) runscript.call(script, false) end end else puts "Project did not have configuration file #{config_file}" exit 1 end end