class Clian::Cli

Constants

DEFAULT_CONFIG_FILE
DEFAULT_CONFIG_HOME

config files

DEFAULT_CONFIG_PATH
NAMED_OPTIONS

Attributes

builder[R]
calendar[R]
config[R]

Public Class Methods

bundler_rbenv_setup(command_path) click to toggle source

rbenv support: If this file is a symlink, and bound to a specific ruby version via rbenv (indicated by RBENV_VERSION), I want to resolve the symlink and re-exec the original executable respecting the .ruby_version which should indicate the right version.

# File lib/clian/cli.rb, line 25
def self.bundler_rbenv_setup(command_path)
  if File.symlink?(command_path) and ENV["RBENV_VERSION"]
    ENV["RBENV_VERSION"] = nil
    shims_path = File.expand_path("shims", ENV["RBENV_ROOT"])
    ENV["PATH"] = shims_path + ":" + ENV["PATH"]
    exec(File.readlink(command_path), *ARGV)
  end

  gemfile = File.expand_path("../../Gemfile", command_path)

  if File.exists?(gemfile + ".lock")
    ENV["BUNDLE_GEMFILE"] = gemfile
    require "bundler/setup"
  end
end
default_config_home() click to toggle source
# File lib/clian/cli.rb, line 14
def self.default_config_home ; DEFAULT_CONFIG_HOME; end
default_config_path() click to toggle source
# File lib/clian/cli.rb, line 15
def self.default_config_path ; DEFAULT_CONFIG_PATH; end
expand_class_option(*names) click to toggle source
# File lib/clian/cli.rb, line 52
def self.expand_class_option(*names)
  expand_named_option(:class, *names)
end
expand_option(*names) click to toggle source
# File lib/clian/cli.rb, line 48
def self.expand_option(*names)
  expand_named_option(:method, *names)
end
named_option(name, options) click to toggle source

register preset options

# File lib/clian/cli.rb, line 44
def self.named_option(name, options)
  ::Clian::Cli::NAMED_OPTIONS[name] = options
end

Private Class Methods

expand_named_option(type, *names) click to toggle source
# File lib/clian/cli.rb, line 56
def self.expand_named_option(type, *names)
  names.each do |name|
    options = ::Clian::Cli::NAMED_OPTIONS[name]
    if type == :class
      class_option name, options
    else
      method_option name, options
    end
  end
end

Public Instance Methods

completions(*command) click to toggle source
# File lib/clian/cli.rb, line 114
def completions(*command)
  help = self.class.commands
  global_options = self.class.class_options

  Clian::Command::Completions.new(help, global_options, command) do |banner|
    custom_completion_for_banner(banner)
  end
end
configuration(name = nil) click to toggle source
# File lib/clian/cli.rb, line 128
def configuration(name = nil)
  puts Clian::Converter::Emacs.new.to_emacs(config.get_value(name))
end
help(command = nil) click to toggle source
Calls superclass method
# File lib/clian/cli.rb, line 89
def help(command = nil)
  super(command)
end
invoke_command(command, *args) click to toggle source
Calls superclass method
# File lib/clian/cli.rb, line 136
def invoke_command(command, *args)
  setup_global_options(command, *args)
  result = super
  teardown
  result
end
version() click to toggle source
# File lib/clian/cli.rb, line 98
def version
  puts Clian::VERSION
end

Private Instance Methods

custom_completion_for_banner(banner) click to toggle source

private

# File lib/clian/cli.rb, line 149
def custom_completion_for_banner(banner)
  return nil
end
exit_on_error() { || ... } click to toggle source
# File lib/clian/cli.rb, line 153
def exit_on_error(&block)
  begin
    yield if block_given?
  rescue Clian::ConfigurationError => e
    STDERR.print "ERROR: #{e.message}.\n"
    exit 1
  end
end
load_plugins() click to toggle source
# File lib/clian/cli.rb, line 192
def load_plugins
  config_path = options[:config] || DEFAULT_CONFIG_PATH
  plugin_dir  = File.dirname(config_path)

  Dir.glob(File.expand_path("plugins/*.rb", plugin_dir)) do |rb|
    require rb
  end
end
setup_global_options(command, *args) click to toggle source
# File lib/clian/cli.rb, line 164
def setup_global_options(command, *args)
  exit_on_error do
    # @config = Clian::Config.create_from_file(options[:config] || DEFAULT_CONFIG_PATH)
    # @builder ||= Clian::Builder.new(@config)
    # if @config.general.tzid
    #  Clian.default_tzid = @config.general.tzid
    #end

    # calname  = options[:calendar] || @config.calendars.first.name
    # @config.general.repository = options[:repository] if options[:repository]

    # self.class.calendar ||= builder.calendar(calname)
    # @calendar = self.class.calendar
  end

  # load_plugins

  # if options[:profile]
  #   require 'profiler'
  #   Profiler__.start_profile
  # end
  # if options[:debug]
  #   require "pp"
  #   $MHC_DEBUG = true
  #   $MHC_DEBUG_FOR_DEVELOPER = true if ENV["MHC_DEBUG_FOR_DEVELOPER"]
  # end
end
teardown() click to toggle source
# File lib/clian/cli.rb, line 201
def teardown
  if options[:profile]
    Profiler__.print_profile($stdout)
  end
end