Class: Autoproj::CLI::Version

Inherits:
Base
  • Object
show all
Defined in:
lib/autoproj/cli/version.rb

Instance Attribute Summary

Attributes inherited from Base

#ws

Instance Method Summary collapse

Methods inherited from Base

#export_env_sh, #initialize, #normalize_command_line_package_selection, #notify_env_sh_updated, #resolve_selection, #resolve_user_selection, validate_options, #validate_options, #validate_user_selection

Methods included from Ops::Tools

#common_options, #create_autobuild_package, #load_autoprojrc, #load_main_initrb

Constructor Details

This class inherits a constructor from Autoproj::CLI::Base

Instance Method Details

#collect_dependencies(dependency, known_dependencies: {}) ⇒ Array<Gem::Dependency>

Collect the dependencies of a given dependency

Parameters:

  • dependency (Gem::Dependency)

    a gem depencency

  • Array<Gem::Dependency] (Array<Gem::Dependency] list of already known dependencies)

    list of already known dependencies

Returns:

  • (Array<Gem::Dependency>)

    all known dependencies



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/autoproj/cli/version.rb', line 39

def collect_dependencies(dependency, known_dependencies: {})
    dep_spec = dependency.matching_specs
    return known_dependencies if dep_spec.empty?

    dep_spec = dep_spec.first
    known_dependencies[dep_spec.name] = dep_spec.version
    dep_spec.dependencies.each do |dep|
        unless known_dependencies.has_key?(dep.name)
            collect_dependencies(dep, known_dependencies: known_dependencies)
        end
    end
    known_dependencies
end

#run(args, options = Hash.new) ⇒ Object

List the version of autoproj and optionally include the installed dependencies with information about the requirement and the actual used version



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/autoproj/cli/version.rb', line 10

def run(args, options = Hash.new)
    puts "autoproj version: #{Autoproj::VERSION}"
    return unless options[:deps]

    dependency = Gem::Deprecate.skip_during do
        Gem::Dependency.new "autoproj", Autoproj::VERSION
    end
    autoproj_spec = dependency.matching_specs
    return if autoproj_spec.empty?

    installed_deps = collect_dependencies(dependency)
    puts "    specified dependencies:"
    autoproj_spec.first.dependencies.each do |dep|
        puts "        #{dep}: #{installed_deps[dep.name] || 'n/a'}"
        installed_deps.delete(dep.name)
    end
    puts "    implicit dependencies:"
    installed_deps.keys.sort.each do |name|
        unless name == "autoproj"
            puts "        #{name}: #{installed_deps[name]}"
        end
    end
end