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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 991d1b77559f0dd2950f7e139720ad30d43f122134d9a1606d77d4669d68739c
4
- data.tar.gz: 0b165c2c86f3e0d7ae9348e9e80021bb810eb8a185d0e74e157b7b456653db4d
3
+ metadata.gz: 764691cb8b83a0076636c83b17fe781c8015f0f68101978d926613f91c64ee5e
4
+ data.tar.gz: f30162cb08bc5691b194861d01871bccc71f979d72d2da14cde3d171e2d10c59
5
5
  SHA512:
6
- metadata.gz: 18e70e6dc8accc71a24d789713d893b56d8bd6bf75fe4c7b2520c2259a58a89456992f67e7ddc13dd21bfd2b711045cfff353f15ee4d00b6708b97252b934139
7
- data.tar.gz: 612df92b0e41b5479a8c7aad8366772436ab94a56e7c4d91a22147c2deba87747aa9623a5bcae3b42dabaaf9637bbed90bdd8e84cb1d7b942fe1a0fbc3fb01ce
6
+ metadata.gz: e0ac6099079bd7e782b149ec9307940dfafa6f104ddd49c8f83cadd4bb0fff6fed5c8b52201f4b346ca5dccc9e08e746a8990eb460bc42b40f9f7eb204a98cb0
7
+ data.tar.gz: f60a2dbdedd58a93178171781bfbb0271b5c311a9bb902b9b51bfd87f1e07962268369c61679e8e30325a556bb64b2b441d2d359a909a4f8dce8b509413a0c91
data/lib/omnicli/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -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
 
@@ -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
- if size
41
- Array.new(size) { |i| arg_value(name, base_type, i) }
42
- else
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
- return nil unless (type_str = ENV.fetch("OMNI_ARG_#{name.upcase}_TYPE", nil))
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
- if type_str.include?("/")
51
- base_type, size = type_str.split("/")
52
- [base_type, size.to_i]
53
- else
54
- [type_str, nil]
55
- end
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, index = nil)
59
- key = ["OMNI_ARG", name.upcase, "VALUE", index].compact.join("_")
60
- value = ENV.fetch(key, nil)
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.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-10-23 00:00:00.000000000 Z
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: