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 +4 -4
- data/CHANGELOG.md +2 -0
- data/README.md +11 -5
- data/dry-cli-completion.gemspec +1 -1
- data/lib/dry/cli/completion/command.rb +2 -2
- data/lib/dry/cli/completion/generator.rb +2 -1
- data/lib/dry/cli/completion/input.rb +23 -10
- data/lib/dry/cli/completion/version.rb +1 -1
- data/lib/dry/cli/completion.rb +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84584d0b8311a6a0608e830090cedb404ab30c92901a21cefff324a9f6ba5119
|
4
|
+
data.tar.gz: ed55444a593eb3811a25f6cc2a0dacc94d1accc06384928846f6d2973aa469e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1188fe5ea0da8bbc42bec08198126558cd2657c422d1a16ac5cf4c08f974a43148bc6f56e13906687d35ae94664ae4994bede0c3609b7dc048f03f4c5c614e2e
|
7
|
+
data.tar.gz: 5e7d91437507f85aff8b94d38e98c93bb5e5a2d28055427e1598504e330591d0c8a15c6b1c885f5ceef6faaf09444645662eddf971992c8cfbdd3d37dd89b6c3
|
data/CHANGELOG.md
CHANGED
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
|
-
|
42
|
-
|
41
|
+
register "cmd1", MyCmd1
|
42
|
+
#....
|
43
43
|
|
44
|
-
|
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
|
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
|
|
data/dry-cli-completion.gemspec
CHANGED
@@ -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
|
-
|
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
|
data/lib/dry/cli/completion.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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.
|
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:
|