Sha256: b4ef24b86f47953915eb316339d6bf3c7a8e5d317d3468910d0e844baf84390f
Contents?: true
Size: 1.67 KB
Versions: 14
Compression:
Stored size: 1.67 KB
Contents
# encoding: utf-8 require 'liquid/boot' require 'mixlib/cli' class CLI include Mixlib::CLI option :name, :short => '-n NAME', :long => '--name NAME', :description => 'Process name', :default => File.basename($0), :proc => ->(value) { $0 = value } option :environment, :short => '-e ENVIRONMENT', :long => '--environment ENVIRONMENT', :description => "Set the daemon environment", :default => "development", :proc => ->(value) { Env.set(value) } option :debug, :short => '-D', :long => '--debug', :description => "Enable debug output", :boolean => true, :default => false, :proc => ->(value) { $conf.mixin(debug: value, log: { level: value ? :debug : :info }); value } option :help, :short => '-h', :long => '--help', :description => "Show this message", :on => :tail, :boolean => true, :show_options => true, :exit => 0 def option(name, args) args[:on] ||= :on args[:boolean] ||= false args[:required] ||= false args[:proc] ||= nil args[:show_options] ||= false args[:exit] ||= nil if args.has_key?(:default) config[name.to_sym] = args[:default] end options[name.to_sym] = args end def self.for(cls, &block) cli = new cli.instance_eval(&block) if block_given? cli.parse_options $conf.reload! $log.info("cli:initialize", cli.config) # infer some variables opts = cli.config.merge({ fqdn: Socket.gethostbyname(Socket.gethostname).first }) # sneak in opts without subclassing cls.allocate.tap do |obj| obj.define_singleton_method(:opts) { opts } obj.send(:initialize) end end end
Version data entries
14 entries across 14 versions & 1 rubygems