Module: Bait::CLI

Defined in:
lib/bait/cli.rb

Constant Summary collapse

USAGE =
%{usage:
* bait .................... alias for bait server
* bait server ............. start the bait server
* bait init ............... setup current directory as a bait project
* bait test <name> ........ execute a script in .bait/*}

Class Method Summary collapse

Class Method Details

.initObject

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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) ⇒ Object



98
99
100
101
102
103
# 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) ⇒ Object

Start the server



13
14
15
16
17
18
19
20
# 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) ⇒ Object

Run a defined phase



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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