omnicli 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/omnicli/VERSION +1 -1
- data/lib/omnicli/errors.rb +7 -0
- data/lib/omnicli/parser.rb +21 -16
- 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: 764691cb8b83a0076636c83b17fe781c8015f0f68101978d926613f91c64ee5e
|
4
|
+
data.tar.gz: f30162cb08bc5691b194861d01871bccc71f979d72d2da14cde3d171e2d10c59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0ac6099079bd7e782b149ec9307940dfafa6f104ddd49c8f83cadd4bb0fff6fed5c8b52201f4b346ca5dccc9e08e746a8990eb460bc42b40f9f7eb204a98cb0
|
7
|
+
data.tar.gz: f60a2dbdedd58a93178171781bfbb0271b5c311a9bb902b9b51bfd87f1e07962268369c61679e8e30325a556bb64b2b441d2d359a909a4f8dce8b509413a0c91
|
data/lib/omnicli/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/lib/omnicli/errors.rb
CHANGED
@@ -12,6 +12,13 @@ module OmniCli
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
# Raised when an invalid type string is encountered
|
16
|
+
class InvalidTypeStringError < Error
|
17
|
+
def initialize(type_str)
|
18
|
+
super("invalid type string: '#{type_str}'")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
15
22
|
# Base class for invalid value errors
|
16
23
|
class InvalidValueError < Error; end
|
17
24
|
|
data/lib/omnicli/parser.rb
CHANGED
@@ -35,29 +35,34 @@ module OmniCli
|
|
35
35
|
type_info = arg_type(name)
|
36
36
|
return nil unless type_info
|
37
37
|
|
38
|
-
base_type, size = type_info
|
38
|
+
base_type, size, group_occurrences = type_info
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
arg_value(name, base_type)
|
40
|
+
return arg_value(name, base_type) unless size
|
41
|
+
|
42
|
+
Array.new(size) do |i|
|
43
|
+
next arg_value(name, base_type, i) unless group_occurrences
|
44
|
+
|
45
|
+
group_size = arg_type(name, i)[1]
|
46
|
+
Array.new(group_size) { |j| arg_value(name, base_type, i, j) }
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
47
|
-
def arg_type(name)
|
48
|
-
|
50
|
+
def arg_type(name, index = nil)
|
51
|
+
env_var = ["OMNI_ARG", name.upcase, "TYPE", index].compact.join("_")
|
52
|
+
return nil unless (type_str = ENV.fetch(env_var, nil))
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
parts = (type_str.split("/") + [nil, nil]).first(3)
|
55
|
+
base_type, size, group_occurrences = parts
|
56
|
+
|
57
|
+
group_occurrences = !group_occurrences.nil?
|
58
|
+
size = size.to_i if size
|
59
|
+
|
60
|
+
[base_type, size, group_occurrences]
|
56
61
|
end
|
57
62
|
|
58
|
-
def arg_value(name, type,
|
59
|
-
|
60
|
-
value = ENV.fetch(
|
63
|
+
def arg_value(name, type, index1 = nil, index2 = nil)
|
64
|
+
env_var = ["OMNI_ARG", name.upcase, "VALUE", index1, index2].compact.join("_")
|
65
|
+
value = ENV.fetch(env_var, nil)
|
61
66
|
|
62
67
|
return default_value(type) if value.nil?
|
63
68
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omnicli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raphaël Beamonte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This package provides functionality to build Omni commands in Ruby
|
14
14
|
email:
|