Class: Clian::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/clian/cli.rb

Constant Summary collapse

CONFIG_HOME =

config files

File.join((ENV["XDG_CONFIG_HOME"] || "~/.config"), basename)
CONFIG_FILE =
"config.yml"
CONFIG_PATH =
File.join(CONFIG_HOME, CONFIG_FILE)
NAMED_OPTIONS =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bundler_rbenv_setup(command_path) ⇒ Object

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.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/clian/cli.rb', line 24

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(__FILE__), *ARGV)
  end

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

  if File.exists?(gemfile + ".lock")
    ENV["BUNDLE_GEMFILE"] = gemfile
    require "bundler/setup"
  end
end

.config_homeObject



13
# File 'lib/clian/cli.rb', line 13

def self.config_home ; CONFIG_HOME; end

.config_pathObject



14
# File 'lib/clian/cli.rb', line 14

def self.config_path ; CONFIG_PATH; end

.expand_class_option(*names) ⇒ Object



51
52
53
# File 'lib/clian/cli.rb', line 51

def self.expand_class_option(*names)
  expand_named_option(:class, *names)
end

.expand_option(*names) ⇒ Object



47
48
49
# File 'lib/clian/cli.rb', line 47

def self.expand_option(*names)
  expand_named_option(:method, *names)
end

.named_option(name, options) ⇒ Object

register preset options



43
44
45
# File 'lib/clian/cli.rb', line 43

def self.named_option(name, options)
  ::Clian::Cli::NAMED_OPTIONS[name] = options
end

Instance Method Details

#completions(*command) ⇒ Object



113
114
115
116
117
# File 'lib/clian/cli.rb', line 113

def completions(*command)
  help = self.class.commands
  global_options = self.class.class_options
  Clian::Command::Completions.new(help, global_options, command, config)
end

#configuration(name = nil) ⇒ Object



124
125
126
# File 'lib/clian/cli.rb', line 124

def configuration(name = nil)
  puts Clian::Converter::Emacs.new.to_emacs(config.get_value(name))
end

#help(command = nil) ⇒ Object



88
89
90
# File 'lib/clian/cli.rb', line 88

def help(command = nil)
  super(command)
end

#versionObject



97
98
99
# File 'lib/clian/cli.rb', line 97

def version
  puts Clian::VERSION
end