Class: Gem::Commands::ManpagesCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
VersionOption
Defined in:
lib/rubygems/commands/manpages_command.rb

Instance Method Summary collapse

Constructor Details

#initializeManpagesCommand

Returns a new instance of ManpagesCommand.



4
5
6
7
8
9
10
11
12
# File 'lib/rubygems/commands/manpages_command.rb', line 4

def initialize
  super "manpages", "Handling manpages in gems",
    command: nil,
    version: Gem::Requirement.default,
    latest:  false,
    all:     false

  add_update_all_option
end

Instance Method Details

#add_update_all_optionObject



18
19
20
21
22
23
# File 'lib/rubygems/commands/manpages_command.rb', line 18

def add_update_all_option
  add_option("-u", "--update-all",
    "Search for manpages in all installed gems and expose them to man") do |_, options|
    options[:update_all] = true
  end
end

#executeObject



25
26
27
28
29
30
31
# File 'lib/rubygems/commands/manpages_command.rb', line 25

def execute
  if options[:update_all]
    update_all
  else
    show_help
  end
end

#update_allObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rubygems/commands/manpages_command.rb', line 33

def update_all
  specs = Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.gems
  specs.each do |*name_and_spec|
    spec = name_and_spec.pop
    next unless Manpages::ManFiles.new(spec.gem_dir).manpages_present? &&
        Manpages::GemVersion.new(spec).latest?

    say "Installing man pages for #{spec.name} #{spec.version}"
    target_dir = File.expand_path("#{Gem.bindir}/../share/man")
    Manpages::Install.new(spec, spec.gem_dir, target_dir).install_manpages
  end
end

#usageObject



14
15
16
# File 'lib/rubygems/commands/manpages_command.rb', line 14

def usage
  "gem manpages"
end