dry-cli-completion 0.9.0.pre.alpha → 1.0.0.pre.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f964195592d079499e1ac64d97966be5041cec718b12d7dbdcad3a13a78a987c
4
- data.tar.gz: 19eb60e90e5d136ac43762f8c897b7f3b9d0197074e12c3a7237ad96230034e2
3
+ metadata.gz: 84584d0b8311a6a0608e830090cedb404ab30c92901a21cefff324a9f6ba5119
4
+ data.tar.gz: ed55444a593eb3811a25f6cc2a0dacc94d1accc06384928846f6d2973aa469e7
5
5
  SHA512:
6
- metadata.gz: 85b055c56a7fd6c9752449275766126f57a51aa2a74e976246b62b25b4a7625cc858b794121d5443b03020cee8407cc00b4fdb79be1c3cbb8b7d738255d10dbf
7
- data.tar.gz: 943acef312431e8176115bea9c3dcdbcef4960640eb409f391a731442b1098f7dbafb5562546c120e00f01524c4087d54b98cd505688923d5de3bcc3a18ff109
6
+ metadata.gz: 1188fe5ea0da8bbc42bec08198126558cd2657c422d1a16ac5cf4c08f974a43148bc6f56e13906687d35ae94664ae4994bede0c3609b7dc048f03f4c5c614e2e
7
+ data.tar.gz: 5e7d91437507f85aff8b94d38e98c93bb5e5a2d28055427e1598504e330591d0c8a15c6b1c885f5ceef6faaf09444645662eddf971992c8cfbdd3d37dd89b6c3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.0-beta Add support for subcommands
4
+
3
5
  ## 0.9.0-alpha First full fledged Implementation
4
6
 
5
7
  ## 0.3.0 Inital Skeleton
data/README.md CHANGED
@@ -38,14 +38,20 @@ Simplest usage is to drop in the `Dry::CLI::Completion::Command` to your existin
38
38
  module MyRegistry
39
39
  extend Dry::CLI::Registry
40
40
 
41
- register "cmd1", MyCmd1
42
- #....
41
+ register "cmd1", MyCmd1
42
+ #....
43
43
 
44
- register "completion", Dry::CLI::Completion::Command[self]
45
- end
44
+ register "completion", Dry::CLI::Completion::Command[self]
46
45
  end
47
46
  ```
48
47
 
48
+ or extend the registry subsequently:
49
+
50
+ ```ruby
51
+ #....
52
+ MyRegistry.register("completion", Dry::CLI::Completion::Command[MyRegistry])
53
+ ```
54
+
49
55
  This will extend your cli for a new command `completion` with following usage:
50
56
 
51
57
  ```sh
@@ -105,7 +111,7 @@ The gem comes with a full-fledged rspec testsuite. To execute all tests run in d
105
111
  $ rspec
106
112
 
107
113
  ### Manual Testing
108
- The foo registry is used in unit test is available as `spec/foo-cli` for manual testing. First source the comepltion script:
114
+ The `Foo::CLI::Command` registry used in unit test is available as `spec/foo-cli` for manual testing. First source the completion script:
109
115
 
110
116
  $ source <(spec/foo-cli completion bash)
111
117
 
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.required_ruby_version = ">= 2.7.6"
27
27
 
28
- spec.add_dependency "completely", "~> 0.4"
28
+ spec.add_dependency "completely", "~> 0.5"
29
29
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/cli/completion"
4
-
5
3
  module Dry
6
4
  class CLI
7
5
  module Completion
6
+ require "dry/cli/completion"
7
+
8
8
  class Command < Dry::CLI::Command
9
9
  desc "Print tab completion script for given shell"
10
10
 
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "input"
4
3
  require "completely"
5
4
 
6
5
  module Dry
7
6
  class CLI
8
7
  module Completion
9
8
  class Generator
9
+ require_relative "input"
10
+
10
11
  def initialize(registry, program_name: nil)
11
12
  @registry = registry
12
13
  @program_name = program_name || Dry::CLI::ProgramName.call
@@ -10,23 +10,36 @@ module Dry
10
10
  end
11
11
 
12
12
  def call(include_aliases:)
13
- nodes = root_node.children.dup
14
- nodes.merge!(root_node.aliases.dup) if include_aliases
15
-
16
- commands = nodes.each_with_object({}) do |(name, sub_node), hash|
17
- next unless sub_node.command
18
- hash[name] = command(sub_node.command, include_aliases: include_aliases)
19
- end
20
-
13
+ commands = extract_commands(root_node, include_aliases: include_aliases)
21
14
  commands.each_with_object({
22
- @program_name => commands.keys + ["help"]
15
+ @program_name => commands.keys.map(&:first).uniq + ["help"]
23
16
  }) do |(name, config), input|
24
- input_line(input, "#{@program_name} #{name}", config[:arguments].shift, config)
17
+ input_line(input, "#{@program_name} #{name.join(" ")}", config[:arguments].shift, config)
25
18
  end
26
19
  end
27
20
 
28
21
  private
29
22
 
23
+ def extract_commands(parent_node, include_aliases:, prefix: [])
24
+ nodes = parent_node.children.dup
25
+ nodes.merge!(parent_node.aliases.dup) if include_aliases
26
+
27
+ nodes.each_with_object({}) do |(name, sub_node), hash|
28
+ key = prefix.dup << name
29
+ hash[key] = if sub_node.command
30
+ command(sub_node.command, include_aliases: include_aliases)
31
+ elsif sub_node.children
32
+ hash.merge!(extract_commands(sub_node, include_aliases: include_aliases, prefix: key))
33
+ {
34
+ options: {},
35
+ arguments: [
36
+ ["subcommands", sub_node.children.keys]
37
+ ]
38
+ }
39
+ end
40
+ end
41
+ end
42
+
30
43
  def root_node
31
44
  @registry.get({}).instance_variable_get(:@node)
32
45
  end
@@ -3,7 +3,7 @@
3
3
  module Dry
4
4
  class CLI
5
5
  module Completion
6
- VERSION = "0.9.0-alpha"
6
+ VERSION = "1.0.0-beta2"
7
7
  end
8
8
  end
9
9
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "completion/version"
4
- require_relative "completion/generator"
5
-
6
3
  module Dry
7
4
  class CLI
8
5
  module Completion
6
+ require_relative "completion/version"
7
+ require_relative "completion/generator"
8
+
9
9
  SUPPORTED_SHELLS = [
10
10
  BASH = "bash",
11
11
  ZSH = "zsh"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-cli-completion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.pre.alpha
4
+ version: 1.0.0.pre.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - rngtng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-20 00:00:00.000000000 Z
11
+ date: 2022-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: completely
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.4'
19
+ version: '0.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.4'
26
+ version: '0.5'
27
27
  description: Extension Command for Dry::CLI which generates a completion script for
28
28
  bash/zsh.
29
29
  email: