ex_aequo_cli 0.1.1 → 0.1.3
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/ex_aequo/cli/args/result.rb +24 -4
- data/lib/ex_aequo/cli/args/view.rb +20 -0
- data/lib/ex_aequo/cli/args.rb +28 -2
- data/lib/ex_aequo/cli/system.rb +30 -0
- data/lib/ex_aequo/cli/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 177a771838a71e6e19364a2cc249d3cbc8d4fdcd57b9fc4a40297d940218c5e3
|
4
|
+
data.tar.gz: dd88326d996afc7b50decef6fddd580b6da2f601778476fb91b75a2f7bc606f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '087b09cf266ec3582c43444a93980bcc323934e8b48df89ebe857becacb40ab81808500ccf17583c584a67276817a1b23659c928caaeaf57f9c63d97faa3b4cc'
|
7
|
+
data.tar.gz: 06db8391dc3ba28688f572723c866da96a4a58339a62897dc95356b849725c524fee01df04b598914c0f4c109943d3585fdfd6df8328e29bc0789e1c289105ee
|
@@ -1,19 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'ostruct'
|
4
|
+
require_relative 'view'
|
4
5
|
module ExAequo
|
5
6
|
module Cli
|
6
7
|
class Args
|
7
8
|
class Result
|
8
9
|
|
9
|
-
|
10
|
+
attr_reader :args, :values
|
10
11
|
|
11
|
-
def
|
12
|
+
def post_process(post_processors)
|
13
|
+
post_processors.each { apply_post_processor it }
|
14
|
+
self
|
15
|
+
end
|
12
16
|
|
13
17
|
private
|
14
18
|
def initialize(*args, **keys)
|
15
|
-
|
16
|
-
values.
|
19
|
+
@args = args
|
20
|
+
@values = OpenStruct.new(keys)
|
21
|
+
end
|
22
|
+
|
23
|
+
def apply_post_processor(postpr)
|
24
|
+
view = View.new(args, values.to_h)
|
25
|
+
result = view.instance_exec(&postpr)
|
26
|
+
case result
|
27
|
+
in [nil, values0]
|
28
|
+
@values = OpenStruct.new(values0)
|
29
|
+
in [args0, nil]
|
30
|
+
@args = args0
|
31
|
+
in [args1, values1]
|
32
|
+
@args = args1
|
33
|
+
@values = OpenStruct.new(values1)
|
34
|
+
else
|
35
|
+
raise "Format of #{result.inspect} not (yet) supported"
|
36
|
+
end
|
17
37
|
end
|
18
38
|
|
19
39
|
def add_args(argums) = argums.flatten.each { args << it }
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'casters'
|
4
|
+
module ExAequo
|
5
|
+
module Cli
|
6
|
+
class Args
|
7
|
+
class View
|
8
|
+
include Casters
|
9
|
+
attr_reader :args, :values
|
10
|
+
|
11
|
+
private
|
12
|
+
def initialize(args, values)
|
13
|
+
@args = args.dup
|
14
|
+
@values = values.dup
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
data/lib/ex_aequo/cli/args.rb
CHANGED
@@ -34,10 +34,30 @@ module ExAequo
|
|
34
34
|
@result = strict ? compute_result(strict:) : Result.new(*@args, **@values)
|
35
35
|
|
36
36
|
check!
|
37
|
-
|
38
37
|
@result
|
39
38
|
end
|
40
39
|
|
40
|
+
def post_process(&blk)
|
41
|
+
raise ArgumentError, 'post_process method needs a block' unless blk
|
42
|
+
|
43
|
+
post_processors << blk
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def post_process_args(&blk)
|
48
|
+
raise ArgumentError, 'post_process_args method needs a block' unless blk
|
49
|
+
|
50
|
+
post_processors << -> { [instance_exec(&blk), nil] }
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
def post_process_values(&blk)
|
55
|
+
raise ArgumentError, 'post_process_values method needs a block' unless blk
|
56
|
+
|
57
|
+
post_processors << -> { [nil, instance_exec(&blk)] }
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
41
61
|
private
|
42
62
|
def initialize(*args, &blk)
|
43
63
|
@aliases = {}
|
@@ -55,6 +75,7 @@ module ExAequo
|
|
55
75
|
checkers << Checker.new(name: 'default constraint', &blk) if blk
|
56
76
|
end
|
57
77
|
|
78
|
+
|
58
79
|
def check! = checkers.each { it.check!(@result) }
|
59
80
|
|
60
81
|
def check_for_spurious!(strict:)
|
@@ -71,7 +92,8 @@ module ExAequo
|
|
71
92
|
flags = @flags.inject @values do |res, (name, flag_desc)|
|
72
93
|
res.merge(name => flag_desc.cast_value(res[name]))
|
73
94
|
end
|
74
|
-
Result.new(*@args, **flags)
|
95
|
+
@result = Result.new(*@args, **flags)
|
96
|
+
run_post_processors
|
75
97
|
end
|
76
98
|
|
77
99
|
def define_flag(flag)
|
@@ -121,6 +143,10 @@ module ExAequo
|
|
121
143
|
@args.shift
|
122
144
|
end
|
123
145
|
|
146
|
+
def post_processors = @__post_processors__ ||= []
|
147
|
+
|
148
|
+
def run_post_processors = @result.post_process(post_processors)
|
149
|
+
|
124
150
|
def set_value(match)
|
125
151
|
name = get_real_name(match)
|
126
152
|
@current_value_name = name
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExAequo
|
4
|
+
module Cli
|
5
|
+
module System extend self
|
6
|
+
|
7
|
+
def cmd_or_puts(cmd, flag:)
|
8
|
+
case flag
|
9
|
+
in true
|
10
|
+
Kernel.system(cmd)
|
11
|
+
in :echo
|
12
|
+
Kernel.send(:`, cmd)
|
13
|
+
in IO
|
14
|
+
flag.puts(cmd)
|
15
|
+
in StringIO
|
16
|
+
flag.puts(cmd)
|
17
|
+
else
|
18
|
+
raise ArgumentError, "illegal flag in cmd_or_puts, accepeted values/types are true, :echo, IO, StringIO"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def cmd_or_debug(cmd, outstream: $stderr)
|
23
|
+
flag = ENV['DEBUG'] ? outstream : true
|
24
|
+
|
25
|
+
cmd_or_puts(cmd, flag:)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
data/lib/ex_aequo/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ex_aequo_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
@@ -15,14 +15,14 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: 0.1.
|
18
|
+
version: 0.1.11
|
19
19
|
type: :runtime
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
23
|
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: 0.1.
|
25
|
+
version: 0.1.11
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,6 +53,8 @@ files:
|
|
53
53
|
- lib/ex_aequo/cli/args/errors.rb
|
54
54
|
- lib/ex_aequo/cli/args/flag_description.rb
|
55
55
|
- lib/ex_aequo/cli/args/result.rb
|
56
|
+
- lib/ex_aequo/cli/args/view.rb
|
57
|
+
- lib/ex_aequo/cli/system.rb
|
56
58
|
- lib/ex_aequo/cli/version.rb
|
57
59
|
homepage: https://codeberg.org/lab419/rb_ex_aequo_cli
|
58
60
|
licenses:
|