Class: Gem::Commands::WhyCommand

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

Overview

Command to show which gems depend on a specific gem

This command helps identify dependency relationships by showing:

  • Direct dependents (–direct): immediate dependents only

  • Deep dependency chains (default): full dependency chains

  • Tree visualization (–tree): hierarchical view

Examples:

Show all dependency chains

gem why concurrent-ruby

Show only direct dependencies

gem why rake --direct

Show tree visualization

gem why concurrent-ruby --tree

Output as JSON

gem why rake --json

Instance Method Summary collapse

Constructor Details

#initializeWhyCommand

Initializes the why command with options



34
35
36
37
38
# File 'lib/rubygems/commands/why_command.rb', line 34

def initialize
  super("why", "Show which gems depend on a specific gem")
  setup_options
  initialize_dependencies
end

Instance Method Details

#descriptionString

Returns long description of the command.

Returns:

  • (String)

    long description of the command



41
42
43
# File 'lib/rubygems/commands/why_command.rb', line 41

def description
  "Show which installed gems depend on a specific gem, including dependency chains"
end

#executevoid

This method returns an undefined value.

Executes the command with the provided arguments



52
53
54
55
# File 'lib/rubygems/commands/why_command.rb', line 52

def execute
  gem_name = validate_gem_name
  route_to_display_mode(gem_name)
end

#usageString

Returns usage string for the command.

Returns:

  • (String)

    usage string for the command



46
47
48
# File 'lib/rubygems/commands/why_command.rb', line 46

def usage
  "#{program_name} GEMNAME [options]"
end