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.



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

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



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

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



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

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

#update_allObject



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

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



16
17
18
# File 'lib/rubygems/commands/manpages_command.rb', line 16

def usage
  "gem manpages"
end