trees 0.3.3 → 0.3.5
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.
- checksums.yaml +4 -4
- data/lib/line.rb +3 -2
- data/lib/trees.rb +23 -14
- data/lib/trie.rb +1 -1
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6ed26c969afc761461ea690075a2c838156cb3309fef5fbac31f219b716c71a8
|
|
4
|
+
data.tar.gz: 47fed5e9edb8a0b5a930ef505beb53381c121dd84cb4d50c89d1b84f6c2875ce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3142f22906faf7f82aed9b56586c4007bbcda629b7d0c98b4099223854e0469317d39f49b44bd55f8fbf378d167a27e5d850a5210bfb0a7177d0547d1e662fa4
|
|
7
|
+
data.tar.gz: 425cf3ce7982b240e8527a34cb2928c071b588896112f2f02b23b428eb887fd017d26ade1f9502a130e9fcd6ea0ef5f6cca8cdd1493ef9c335ddef7aca98f55d
|
data/lib/line.rb
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
module Trees
|
|
4
4
|
class Line
|
|
5
5
|
attr_reader :path, :params
|
|
6
|
-
attr_accessor :summary, :execute
|
|
6
|
+
attr_accessor :summary, :example, :execute
|
|
7
7
|
|
|
8
|
-
def initialize(path:, params:
|
|
8
|
+
def initialize(path:, params: [])
|
|
9
9
|
@path = path
|
|
10
10
|
@params = params
|
|
11
11
|
|
|
12
12
|
@summary = nil
|
|
13
|
+
@example = nil
|
|
13
14
|
@execute = nil
|
|
14
15
|
end
|
|
15
16
|
end
|
data/lib/trees.rb
CHANGED
|
@@ -4,20 +4,18 @@ require_relative 'line'
|
|
|
4
4
|
require_relative 'trie'
|
|
5
5
|
|
|
6
6
|
module Trees
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
TOKEN_SEPARATOR = ' '.freeze
|
|
7
|
+
TOKEN_SEPARATOR = ' '
|
|
10
8
|
|
|
11
9
|
def line(path, &block)
|
|
12
10
|
current_path << path
|
|
13
11
|
current_path_joined = current_path.join(TOKEN_SEPARATOR)
|
|
14
12
|
|
|
15
|
-
@current_line = Line.new(path: current_path_joined, params: block.parameters.
|
|
13
|
+
@current_line = Line.new(path: current_path_joined, params: block.parameters.map(&:last))
|
|
16
14
|
|
|
17
15
|
lines[current_path_joined] = @current_line
|
|
18
16
|
trie.merge(line: @current_line)
|
|
19
17
|
|
|
20
|
-
block.call if block_given?
|
|
18
|
+
block.call(**stub_required_keywords(block:)) if block_given?
|
|
21
19
|
|
|
22
20
|
current_path.pop
|
|
23
21
|
end
|
|
@@ -25,14 +23,20 @@ module Trees
|
|
|
25
23
|
def summary(&block)
|
|
26
24
|
@current_line.summary = block
|
|
27
25
|
end
|
|
26
|
+
alias s summary
|
|
27
|
+
|
|
28
|
+
def example(&block)
|
|
29
|
+
@current_line.example = block
|
|
30
|
+
end
|
|
31
|
+
alias e example
|
|
28
32
|
|
|
29
33
|
def execute(&block)
|
|
30
34
|
@current_line.execute = block
|
|
31
35
|
end
|
|
36
|
+
alias x execute
|
|
32
37
|
|
|
33
38
|
def run(tokens)
|
|
34
39
|
results = trie.match(tokens:)
|
|
35
|
-
|
|
36
40
|
execute_block(results:)
|
|
37
41
|
end
|
|
38
42
|
|
|
@@ -42,19 +46,24 @@ module Trees
|
|
|
42
46
|
while results.count > 0
|
|
43
47
|
result = results.pop
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
result.line.params.values.each do |param|
|
|
47
|
-
result.line.execute.binding.local_variable_set(param, result.params[param])
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
result.line.execute.call
|
|
49
|
+
next unless result.line.execute
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
result.line.params.each do |param|
|
|
52
|
+
result.line.execute.binding.local_variable_set(param, result.params[param]) if result.params.key?(param)
|
|
53
53
|
end
|
|
54
|
+
|
|
55
|
+
result.line.execute.call
|
|
56
|
+
|
|
57
|
+
return true
|
|
54
58
|
end
|
|
55
59
|
|
|
56
60
|
false
|
|
57
|
-
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# The "line" block defines the params that the "execute" child block will use later but doesn't itself execute user input.
|
|
64
|
+
def stub_required_keywords(block:)
|
|
65
|
+
block.parameters.filter_map { |type, name| [name, nil] if type == :keyreq }.to_h
|
|
66
|
+
end
|
|
58
67
|
|
|
59
68
|
def current_path
|
|
60
69
|
@current_path ||= []
|
data/lib/trie.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: trees
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
42
|
version: '0'
|
|
43
43
|
requirements: []
|
|
44
|
-
rubygems_version:
|
|
44
|
+
rubygems_version: 3.7.2
|
|
45
45
|
specification_version: 4
|
|
46
46
|
summary: A CLI framework where you write the literal terminal commands.
|
|
47
47
|
test_files: []
|