Class: Clian::Cli

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

Constant Summary collapse

DEFAULT_CONFIG_HOME =

config files

File.join((ENV["XDG_CONFIG_HOME"] ||
"~/.config"), basename)
DEFAULT_CONFIG_FILE =
"config.yml"
DEFAULT_CONFIG_PATH =
File.join(DEFAULT_CONFIG_HOME, DEFAULT_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.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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_homeObject



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

def self.default_config_home ; DEFAULT_CONFIG_HOME; end

.default_config_pathObject



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

def self.default_config_path ; DEFAULT_CONFIG_PATH; end

.expand_class_option(*names) ⇒ Object



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

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

.expand_option(*names) ⇒ Object



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

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

.named_option(name, options) ⇒ Object

register preset options



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

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

Instance Method Details

#completions(*command) ⇒ Object



114
115
116
117
118
# 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, config)
end

#configuration(name = nil) ⇒ Object



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

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

#help(command = nil) ⇒ Object



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

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

#versionObject



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

def version
  puts Clian::VERSION
end