Class: Rwm::Commands::List
- Inherits:
-
Object
- Object
- Rwm::Commands::List
- Defined in:
- lib/rwm/commands/list.rb
Instance Method Summary collapse
-
#initialize(argv) ⇒ List
constructor
A new instance of List.
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ List
Returns a new instance of List.
6 7 8 |
# File 'lib/rwm/commands/list.rb', line 6 def initialize(argv) @argv = argv end |
Instance Method Details
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rwm/commands/list.rb', line 10 def run workspace = Workspace.find packages = workspace.packages if packages.empty? puts "No packages found." return 0 end graph = DependencyGraph.load(workspace) # Calculate column widths name_width = [packages.map { |p| p.name.length }.max, 4].max type_width = 4 path_width = [packages.map { |p| p.relative_path(workspace.root).length }.max, 4].max # Header puts format("%-#{name_width}s %-#{type_width}s %-#{path_width}s %s", "Name", "Type", "Path", "Dependencies") puts format("%-#{name_width}s %-#{type_width}s %-#{path_width}s %s", "-" * name_width, "-" * type_width, "-" * path_width, "-" * 12) # Rows packages.each do |pkg| deps = graph.dependencies(pkg.name) dep_str = deps.empty? ? "(none)" : deps.sort.join(", ") puts format("%-#{name_width}s %-#{type_width}s %-#{path_width}s %s", pkg.name, pkg.type, pkg.relative_path(workspace.root), dep_str) end 0 end |