Class: Librarian::Cli

Inherits:
Thor
  • Object
show all
Extended by:
Particularity
Includes:
Thor::Actions
Defined in:
lib/librarian/cli.rb,
lib/librarian/cli/manifest_presenter.rb

Direct Known Subclasses

Mock::Cli

Defined Under Namespace

Modules: Particularity Classes: ManifestPresenter

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Particularity

root_module

Constructor Details

#initializeCli

Returns a new instance of Cli


53
54
55
56
57
58
59
60
61
62
# 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

Class Attribute Details

.environmentObject

Returns the value of attribute environment


42
43
44
# File 'lib/librarian/cli.rb', line 42

def environment
  @environment
end

Class Method Details

.bin!Object


25
26
27
28
# File 'lib/librarian/cli.rb', line 25

def bin!
  status = with_environment { returning_status { start } }
  exit status
end

.returning_statusObject


30
31
32
33
34
35
36
37
38
39
40
# 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_environmentObject


44
45
46
47
48
49
50
# 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

Instance Method Details

#cleanObject


102
103
104
105
# File 'lib/librarian/cli.rb', line 102

def clean
  ensure!
  clean!
end

#config(key = nil, value = nil) ⇒ Object


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# 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

#initObject


146
147
148
# File 'lib/librarian/cli.rb', line 146

def init
  puts "Nothing to do."
end

#outdatedObject


123
124
125
126
127
128
129
130
# 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) ⇒ Object


136
137
138
139
140
141
142
143
# 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) ⇒ Object


110
111
112
113
114
115
116
117
118
# File 'lib/librarian/cli.rb', line 110

def update(*names)
  ensure!
  if names.empty?
    resolve!(:force => true)
  else
    update!(:names => names)
  end
  install!
end

#versionObject


65
66
67
68
# File 'lib/librarian/cli.rb', line 65

def version
  say "librarian-#{environment.version}"
  say "librarian-#{environment.adapter_name}-#{environment.adapter_version}"
end