lux-hammer 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/lib/lux-hammer.rb +22 -4
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5fc940f903d901587d17cd94c6f34eed5f92de64ded400a882228e34037cad1
4
- data.tar.gz: 480bd5d42e755ea6c92d956e48eb146777718e6be46a74042b9c8f0192479c27
3
+ metadata.gz: 8e861fb5cdf9bbcc0533942927d96f35348fbb50614c1dd50b16279f1d81d2d3
4
+ data.tar.gz: 1a31f522be7d9c75847ce820169da0c5b9a4418522c224d3d284ce004ecbcd2d
5
5
  SHA512:
6
- metadata.gz: 33bf95c45d0eba2bf3d37aa55f7dcb6dcf317c25b3badeaba965f00f582c27cb92285db07f360e290c3c8d41f82f575bbb6171583bd5cce106b065843f7ad08d
7
- data.tar.gz: 2dec31a7d86c8a3f525fa2beac4134576a634141001550b9226eed0ed723f6768a56bf404be4fbdf239a954eccb094be060695838a7c25cd820aae72af7db186
6
+ metadata.gz: a1d7af3b3523903b10bf5a1b0af1d4d1c340b8a1a6736d6b9b0884f0cc0adca7eaa46079dfb24274147043c4e79b9a8ea497afcb7b6c80389ec73c4ee302d28f
7
+ data.tar.gz: e436739c8da3cb6dcfbd64135405930e70ba07eab53a5f1c880d3240319ce9c77118d61ba6fb766ef5817dfa54b0fa37fe17d1167236b4221afc156e04f3463f
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
data/lib/lux-hammer.rb CHANGED
@@ -388,6 +388,20 @@ class Hammer
388
388
  pair&.last
389
389
  end
390
390
 
391
+ # Returns the command at the parent that shares its name with this
392
+ # namespace. E.g. for path "gem:version" returns the `version` command
393
+ # in the `gem` namespace (if defined), so `gem:version:` listings can
394
+ # include `gem:version` itself at the top.
395
+ def find_namespace_sibling(canonical)
396
+ parts = canonical.to_s.split(':')
397
+ return nil if parts.empty?
398
+ parent = self
399
+ parts[0..-2].each do |seg|
400
+ parent = parent.namespaces[seg] or return nil
401
+ end
402
+ parent.commands[parts.last]
403
+ end
404
+
391
405
  # Walk "ns1:ns2:cmd" -> [command, owning_class, canonical_path].
392
406
  # Returns [nil, nil, nil] if any segment is missing or the final
393
407
  # segment isn't a command. canonical_path uses the canonical name
@@ -581,11 +595,15 @@ class Hammer
581
595
 
582
596
  def print_namespace_help(prefix, ns, full: false)
583
597
  Shell.say "Usage: #{program_name} #{prefix}:COMMAND [ARGS]", :cyan
584
- if full
585
- ns.each_command(prefix) { |path, c| print_full_block(path, c) unless c.desc.empty? }
586
- else
598
+ rows = []
599
+ sibling = find_namespace_sibling(prefix)
600
+ rows << [prefix, sibling] if sibling && !sibling.desc.empty?
601
+ ns.each_command(prefix) { |path, c| rows << [path, c] unless c.desc.empty? }
602
+ unless rows.empty?
587
603
  Shell.say ''
588
- print_command_list(ns, prefix)
604
+ Shell.say 'Commands:', :yellow
605
+ width = rows.map { |path, _| path.length }.max
606
+ emit_rows(rows.sort_by { |path, _| [path.count(':'), path] }, width)
589
607
  end
590
608
  print_global_flags
591
609
  print_footer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lux-hammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic