class Cs::Service::Cli

Cli

Constants

CONFIG_FILES
ENVS
PROJECTS

Public Instance Methods

env(env_name = nil) click to toggle source
# File lib/cs/service/cli.rb, line 35
def env(env_name = nil)
  if env_name.nil?
    print_env
  elsif ENV[env_name]
    puts "#{env_name}=#{ENV[env_name]}"
  else
    say "#{env_name} is blank", :yellow
  end
  say "\nConfig Files:"
  fetch_config_files
  say "详见 cs-service help env"
end
help(command = nil, subcommand = false) click to toggle source
Calls superclass method
# File lib/cs/service/cli.rb, line 80
def help(command = nil, subcommand = false)
  say Motd.msg unless command
  super(command, subcommand)
end
info(name = nil) click to toggle source
# File lib/cs/service/cli.rb, line 49
def info(name = nil)
  # invoke(:env)
  run_eye(:info, name)
end
load_conf() click to toggle source
# File lib/cs/service/cli.rb, line 21
def load_conf
  invoke(:env)
  quit if options[:force]
  run_eye(:load, File.join(HOME_PATH, 'config/caishuo.eye'))
end
log(project = nil) click to toggle source
# File lib/cs/service/cli.rb, line 75
def log(project = nil)
  run_eye(:trace, project || PROJECTS)
end
quit() click to toggle source
# File lib/cs/service/cli.rb, line 69
def quit
  stop
  run_eye(:quit)
end
version() click to toggle source
# File lib/cs/service/cli.rb, line 86
def version
  say Cs::Service::VERSION, :green
end

Private Instance Methods

check_config_file(file_root) click to toggle source

判断当个配置文件是否存在

# File lib/cs/service/cli.rb, line 117
def check_config_file(file_root)
  file = File.join(file_root, 'config', 'project.yml')
  if File.exist?(file)
    say("Found: #{file}", :green)
    file
  else
    say("Not Found: #{file}", :red)
    nil
  end
end
current_root() click to toggle source

当前root

# File lib/cs/service/cli.rb, line 129
def current_root
  File.expand_path('.')
end
fetch_config_files() click to toggle source

查找有效的配置文件

# File lib/cs/service/cli.rb, line 108
def fetch_config_files
  config_files = CONFIG_FILES.values.compact.uniq.map do |file|
    check_config_file(file)
  end.compact
  return config_files unless config_files == []
  check_config_file(current_root).nil? ? [] : File.join(current_root, 'config', 'project.yml')
end
print_env() click to toggle source
rack_env() click to toggle source

当前运行环境

# File lib/cs/service/cli.rb, line 134
def rack_env
  ENV['RACK_ENV'] || 'development'
end
run_eye(command, *args) click to toggle source
# File lib/cs/service/cli.rb, line 102
def run_eye(command, *args)
  ENV['CURRENT_PWD'] = current_root
  ::Eye::Cli.new.send(command, *args)
end