dry-cli-completion 0.9.0.pre.alpha → 1.0.0.pre.beta1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfc6870147f7e3d9460cfe07f349ada53c96554e6ea4c986561063526c465131
|
4
|
+
data.tar.gz: dc1abfb5043af486f5a80cc629583e5e87b9586478d5f51596e5bb5aec7b8b25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 239d210f27002efb93e3e51d0bf649057d7f516bdd7e038b98d19aa03dce99993ef2a20fb1db27c9980c9fed4e73e7983c796e37cd7048de3203cbec6d54a11d
|
7
|
+
data.tar.gz: 6806b30859960dcc9d112811ceba66111d02a6d4002e1ebe4bb05a923efda14f492681549a3e74a81f0d8701c1fdbbb632f032320f64f1a5303958ed4de11eb0
|
@@ -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.beta1
|
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-
|
11
|
+
date: 2022-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: completely
|