Nephos/NephosRubyServer

View on GitHub
bin/nephos-status

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby

require 'colorize'
require 'optparse'

require_relative '../lib/nephos-server/version'
require_relative '../lib/nephos-server/bin-helpers'

opt = OptionParser.new do |opts|
  opts.banner = "Usage<#{Nephos::VERSION}>: nephos-status [appli directory]"

  opts.on("--rm") do
    $remove = true
  end

  opts.on("--debug") do
    $debug = true
  end

end.parse!

$dir = opt[0] || "."

begin
  if Dir.exist? $dir
    $gfl = File.expand_path "Gemfile.lock", $dir
    if not File.exist? $gfl or
       not File.read($gfl).split.index("nephos-server")
      raise "\"#{$dir}\" is not a valid nephos-server application"
    else
      data = File.read($gfl).split("\n").map(&:strip)
      version = data.map{|e| e.match(/nephos-server \((?<version>\d+(\.\d+)+)\)/) }.compact.first
      raise "\"#{$gfl}\" doesn't contain a valid nephos-server version" unless version
      version = version["version"]
      path = $gfl.gsub(/Gemfile\.lock$/, "")
      n_controllers = 0
      Dir[File.expand_path 'app/*.rb'].each do |f|
        n_controllers += 1 if File.read(f).include? "< Nephos::Controller"
      end
      puts "Full path: #{path}"
      puts "Installed nephos-version: #{version}"
      puts "Controllers (#{n_controllers})"
      daemon = $dir + "/.pid"
      puts "The application is deploye as daemon (#{File.read(daemon)})" if File.exist? daemon
    end
  else
    raise "\"#{$dir}\" is not a valid directory"
  end

rescue => err
  puts "Error:".red + " #{err.message}"
  puts err.backtrace
end