Sha256: 2be0380e69a10072358932e9039ec084371e119147929e99db1b4d22d778092c

Contents?: true

Size: 1.7 KB

Versions: 2

Compression:

Stored size: 1.7 KB

Contents

require 'bait'

module Bait
  module CLI
    USAGE = %{usage:
    * bait .................... alias for bait server
    * bait server ............. start the bait server
    * bait init ............... setup current directory as a bait project
    * bait test ............... simulate this repo being tested with bait}

    ##
    # Start the server
    def self.server
      puts "** Bait/#{Bait::VERSION} booting up in #{Bait.env} environment"
      if Bait.env == "production" && Bait.assets.missing?
        Bait.assets.precompile
      end
      require 'bait/api'
      Bait::Api.run!
    end

    ##
    # Run the test suite script in .bait/test.sh
    def self.test
      script = File.join(Dir.pwd, ".bait", "test.sh")
      unless File.executable? script
        puts "Project did not have executable #{script}"
        puts "Run 'bait init' to create it"
        exit 1
      else
        system script
        status = $?.exitstatus
        puts "exited with status #{status}"
        exit status
      end
    end

    ##
    # Create .bait/ and executable .bait/test.sh
    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 edit me"
        end
        File.chmod(0744, script)
        puts "Created executable script #{script}"
      end
    end

    def self.method_missing method
      unless method.to_sym == :help
        puts "Command not found: #{method}"
      end
      puts USAGE
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bait-0.5.6 lib/bait/cli.rb
bait-0.5.5 lib/bait/cli.rb