class Librarian::Cli
Attributes
environment[RW]
Public Class Methods
bin!()
click to toggle source
# File lib/librarian/cli.rb, line 25 def bin! status = with_environment { returning_status { start } } exit status end
new(*)
click to toggle source
Calls superclass method
# File lib/librarian/cli.rb, line 53 def initialize(*) super the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell) environment.ui = UI::Shell.new(the_shell) environment.ui.be_quiet! if options["quiet"] environment.ui.debug! if options["verbose"] environment.ui.debug_line_numbers! if options["verbose"] && options["line-numbers"] write_debug_header end
returning_status() { || ... }
click to toggle source
# File lib/librarian/cli.rb, line 30 def returning_status yield 0 rescue Librarian::Error => e environment.ui.error e.message environment.ui.debug e.backtrace.join("\n") e.respond_to?(:status_code) && e.status_code || 1 rescue Interrupt => e environment.ui.error "\nQuitting..." 1 end
with_environment() { |environment| ... }
click to toggle source
# File lib/librarian/cli.rb, line 44 def with_environment environment = root_module.environment_class.new self.environment, orig_environment = environment, self.environment yield(environment) ensure self.environment = orig_environment end
Public Instance Methods
clean()
click to toggle source
# File lib/librarian/cli.rb, line 102 def clean ensure! clean! end
config(key = nil, value = nil)
click to toggle source
# File lib/librarian/cli.rb, line 76 def config(key = nil, value = nil) if key raise Error, "cannot set both value and delete" if value && options["delete"] if options["delete"] scope = config_scope(true) environment.config_db[key, scope] = nil elsif value scope = config_scope(true) environment.config_db[key, scope] = value else scope = config_scope(false) if value = environment.config_db[key, scope] prefix = scope ? "#{key} (#{scope})" : key say "#{prefix}: #{value}" end end else environment.config_db.keys.each do |key| say "#{key}: #{environment.config_db[key]}" end end end
init()
click to toggle source
# File lib/librarian/cli.rb, line 146 def init puts "Nothing to do." end
outdated()
click to toggle source
# File lib/librarian/cli.rb, line 123 def outdated ensure! resolution = environment.lock manifests = resolution.manifests.sort_by(&:name) manifests.select(&:outdated?).each do |manifest| say "#{manifest.name} (#{manifest.version} -> #{manifest.latest.version})" end end
show(*names)
click to toggle source
# File lib/librarian/cli.rb, line 136 def show(*names) ensure! if environment.lockfile_path.file? manifest_presenter.present(names, :detailed => options["detailed"]) else raise Error, "Be sure to install first!" end end
update(*names)
click to toggle source
# File lib/librarian/cli.rb, line 110 def update(*names) ensure! if names.empty? resolve!(:force => true) else update!(:names => names) end install! end
version()
click to toggle source
# File lib/librarian/cli.rb, line 65 def version say "librarian-#{environment.version}" say "librarian-#{environment.adapter_name}-#{environment.adapter_version}" end
Private Instance Methods
clean!(options = { })
click to toggle source
# File lib/librarian/cli.rb, line 160 def clean!(options = { }) Action::Clean.new(environment, options).run end
config_scope(exclusive)
click to toggle source
# File lib/librarian/cli.rb, line 213 def config_scope(exclusive) g, l = "global", "local" if exclusive options[g] ^ options[l] or raise Error, "must set either #{g} or #{l}" else options[g] && options[l] and raise Error, "cannot set both #{g} and #{l}" end options[g] ? :global : options[l] ? :local : nil end
debug(*args, &block)
click to toggle source
# File lib/librarian/cli.rb, line 205 def debug(*args, &block) environment.logger.debug(*args, &block) end
ensure!(options = { })
click to toggle source
# File lib/librarian/cli.rb, line 156 def ensure!(options = { }) Action::Ensure.new(environment, options).run end
environment()
click to toggle source
# File lib/librarian/cli.rb, line 152 def environment self.class.environment end
install!(options = { })
click to toggle source
# File lib/librarian/cli.rb, line 164 def install!(options = { }) Action::Install.new(environment, options).run end
manifest_presenter()
click to toggle source
# File lib/librarian/cli.rb, line 176 def manifest_presenter ManifestPresenter.new(self, environment.lock.manifests) end
relative_path_to(path)
click to toggle source
# File lib/librarian/cli.rb, line 209 def relative_path_to(path) environment.logger.relative_path_to(path) end
resolve!(options = { })
click to toggle source
# File lib/librarian/cli.rb, line 168 def resolve!(options = { }) Action::Resolve.new(environment, options).run end
update!(options = { })
click to toggle source
# File lib/librarian/cli.rb, line 172 def update!(options = { }) Action::Update.new(environment, options).run end
write_debug_header()
click to toggle source
# File lib/librarian/cli.rb, line 180 def write_debug_header debug { "Ruby Version: #{RUBY_VERSION}" } debug { "Ruby Platform: #{RUBY_PLATFORM}" } debug { "Rubinius Version: #{Rubinius::VERSION}" } if defined?(Rubinius) debug { "JRuby Version: #{JRUBY_VERSION}" } if defined?(JRUBY_VERSION) debug { "Rubygems Version: #{Gem::VERSION}" } debug { "Librarian Version: #{environment.version}" } debug { "Librarian Adapter: #{environment.adapter_name}"} debug { "Librarian Adapter Version: #{environment.adapter_version}" } debug { "Project: #{environment.project_path}" } debug { "Specfile: #{relative_path_to(environment.specfile_path)}" } debug { "Lockfile: #{relative_path_to(environment.lockfile_path)}" } debug { "Git: #{Source::Git::Repository.bin}" } debug { "Git Version: #{Source::Git::Repository.git_version}" } debug { "Git Environment Variables:" } git_env = ENV.to_a.select{|(k, v)| k =~ /\AGIT/}.sort_by{|(k, v)| k} if git_env.empty? debug { " (empty)" } else git_env.each do |(k, v)| debug { " #{k}=#{v}"} end end end