foobara-sh-cli-connector 0.0.15 → 0.0.16
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/CHANGELOG.md +4 -0
- data/src/sh_cli_connector/inputs_parser/option/attributes.rb +10 -2
- data/src/sh_cli_connector/inputs_parser/option/flag.rb +12 -3
- data/src/sh_cli_connector/inputs_parser/option/model.rb +10 -2
- data/src/sh_cli_connector/inputs_parser/option.rb +33 -6
- data/src/sh_cli_connector/inputs_parser.rb +7 -5
- data/src/sh_cli_connector/request.rb +1 -1
- data/src/sh_cli_connector.rb +11 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dcda00a8c3db19bc9c8fc042426474b84556ba1194f7e1ed8342f611591a09a
|
4
|
+
data.tar.gz: 9d6eebb26d928a7fa95d37e9212d23a0cf1323d870c0c04f5292de9fbb06155d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aab655719d3de0f52e7d0bbce98d25c3351c8f09ac5fb755811748b00c7072c532cbe22d76a650602da993f159e14eeb1a201948e095a5bc4cef19ec3a0a2d0f
|
7
|
+
data.tar.gz: 10f7d27ca54c33198040919acfb1376489b8f2fa1a25b1a264e589179b48cd1c975434b086342f319f82d501bb0e938889d614c8938db2d4309cb960302a12fd
|
data/CHANGELOG.md
CHANGED
@@ -9,7 +9,14 @@ module Foobara
|
|
9
9
|
attribute_type.extends?(BuiltinTypes[:attributes])
|
10
10
|
end
|
11
11
|
|
12
|
-
def attribute_to_options(
|
12
|
+
def attribute_to_options(
|
13
|
+
attribute_name,
|
14
|
+
attribute_type:,
|
15
|
+
prefix:,
|
16
|
+
is_required:,
|
17
|
+
default:,
|
18
|
+
always_prefix_inputs:
|
19
|
+
)
|
13
20
|
sub_required_attributes = if is_required
|
14
21
|
attribute_type.declaration_data[:required] || []
|
15
22
|
end || []
|
@@ -22,7 +29,8 @@ module Foobara
|
|
22
29
|
attribute_type: sub_attribute_type,
|
23
30
|
prefix: [*prefix, *attribute_name],
|
24
31
|
is_required: is_required && sub_required_attributes.include?(sub_attribute_name),
|
25
|
-
default: defaults[sub_attribute_name]
|
32
|
+
default: defaults[sub_attribute_name],
|
33
|
+
always_prefix_inputs:
|
26
34
|
)
|
27
35
|
end.flatten
|
28
36
|
end
|
@@ -9,7 +9,14 @@ module Foobara
|
|
9
9
|
attribute_type.extends?(BuiltinTypes[:boolean])
|
10
10
|
end
|
11
11
|
|
12
|
-
def attribute_to_options(
|
12
|
+
def attribute_to_options(
|
13
|
+
attribute_name,
|
14
|
+
attribute_type:,
|
15
|
+
prefix:,
|
16
|
+
is_required:,
|
17
|
+
default:,
|
18
|
+
always_prefix_inputs:
|
19
|
+
)
|
13
20
|
klasses = []
|
14
21
|
|
15
22
|
klasses << OnFlag if default != true
|
@@ -21,7 +28,8 @@ module Foobara
|
|
21
28
|
attribute_type:,
|
22
29
|
is_required:,
|
23
30
|
default:,
|
24
|
-
prefix
|
31
|
+
prefix:,
|
32
|
+
always_prefix_inputs:
|
25
33
|
)
|
26
34
|
else
|
27
35
|
klasses.map do |klass|
|
@@ -30,7 +38,8 @@ module Foobara
|
|
30
38
|
attribute_type:,
|
31
39
|
is_required:,
|
32
40
|
default:,
|
33
|
-
prefix
|
41
|
+
prefix:,
|
42
|
+
always_prefix_inputs:
|
34
43
|
)
|
35
44
|
end
|
36
45
|
end
|
@@ -9,13 +9,21 @@ module Foobara
|
|
9
9
|
attribute_type.extends?(BuiltinTypes[:model]) && !attribute_type.extends?(BuiltinTypes[:entity])
|
10
10
|
end
|
11
11
|
|
12
|
-
def attribute_to_options(
|
12
|
+
def attribute_to_options(
|
13
|
+
attribute_name,
|
14
|
+
attribute_type:,
|
15
|
+
prefix:,
|
16
|
+
is_required:,
|
17
|
+
default:,
|
18
|
+
always_prefix_inputs:
|
19
|
+
)
|
13
20
|
Option.attribute_to_options(
|
14
21
|
attribute_name,
|
15
22
|
attribute_type: attribute_type.target_class.attributes_type,
|
16
23
|
prefix:,
|
17
24
|
is_required:,
|
18
|
-
default
|
25
|
+
default:,
|
26
|
+
always_prefix_inputs:
|
19
27
|
)
|
20
28
|
end
|
21
29
|
end
|
@@ -4,7 +4,14 @@ module Foobara
|
|
4
4
|
class InputsParser
|
5
5
|
class Option
|
6
6
|
class << self
|
7
|
-
def attribute_to_options(
|
7
|
+
def attribute_to_options(
|
8
|
+
attribute_name,
|
9
|
+
attribute_type:,
|
10
|
+
prefix:,
|
11
|
+
is_required:,
|
12
|
+
default:,
|
13
|
+
always_prefix_inputs:
|
14
|
+
)
|
8
15
|
[Model, Attributes, Flag].each do |klass|
|
9
16
|
if klass.applicable?(attribute_type)
|
10
17
|
return klass.attribute_to_options(
|
@@ -12,23 +19,39 @@ module Foobara
|
|
12
19
|
attribute_type:,
|
13
20
|
prefix:,
|
14
21
|
is_required:,
|
15
|
-
default
|
22
|
+
default:,
|
23
|
+
always_prefix_inputs:
|
16
24
|
)
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
20
|
-
new(
|
28
|
+
new(
|
29
|
+
attribute_name:,
|
30
|
+
attribute_type:,
|
31
|
+
prefix:,
|
32
|
+
is_required:,
|
33
|
+
default:,
|
34
|
+
always_prefix_inputs:
|
35
|
+
)
|
21
36
|
end
|
22
37
|
end
|
23
38
|
|
24
|
-
attr_accessor :attribute_type, :attribute_name, :is_required, :prefix, :default
|
39
|
+
attr_accessor :attribute_type, :attribute_name, :is_required, :prefix, :default, :always_prefix_inputs
|
25
40
|
|
26
|
-
def initialize(
|
41
|
+
def initialize(
|
42
|
+
attribute_name:,
|
43
|
+
attribute_type:,
|
44
|
+
prefix:,
|
45
|
+
is_required:,
|
46
|
+
default:,
|
47
|
+
always_prefix_inputs:
|
48
|
+
)
|
27
49
|
self.attribute_type = attribute_type
|
28
50
|
self.attribute_name = attribute_name
|
29
51
|
self.prefix = prefix
|
30
52
|
self.is_required = is_required
|
31
53
|
self.default = default
|
54
|
+
self.always_prefix_inputs = always_prefix_inputs
|
32
55
|
|
33
56
|
# TODO: support this
|
34
57
|
# args << attributes_type.declaration_data[:one_of] if attributes_type.declaration_data.key?(:one_of)
|
@@ -96,7 +119,11 @@ module Foobara
|
|
96
119
|
end
|
97
120
|
|
98
121
|
def _prefixed_name(full_paths)
|
99
|
-
|
122
|
+
if always_prefix_inputs
|
123
|
+
full_path.join("_")
|
124
|
+
else
|
125
|
+
_non_colliding_path(full_paths).join("_")
|
126
|
+
end
|
100
127
|
end
|
101
128
|
|
102
129
|
def _long_option_name(prefixed_name)
|
@@ -18,10 +18,11 @@ module Foobara
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
attr_accessor :inputs_type, :parser, :current_array, :result
|
21
|
+
attr_accessor :inputs_type, :parser, :current_array, :result, :always_prefix_inputs
|
22
22
|
|
23
|
-
def initialize(inputs_type)
|
23
|
+
def initialize(inputs_type, always_prefix_inputs:)
|
24
24
|
self.inputs_type = inputs_type
|
25
|
+
self.always_prefix_inputs = always_prefix_inputs
|
25
26
|
self.parser = OptionParser.new
|
26
27
|
|
27
28
|
setup_parser
|
@@ -53,7 +54,7 @@ module Foobara
|
|
53
54
|
parser.set_summary_indent " "
|
54
55
|
|
55
56
|
if inputs_type&.element_types&.any?
|
56
|
-
attribute_to_option
|
57
|
+
attribute_to_option(always_prefix_inputs:)
|
57
58
|
# This feels wrong but the parser callback needs to access our result.
|
58
59
|
# TODO: figure out this smell and fix it
|
59
60
|
option_set.prepare_parser(self)
|
@@ -61,12 +62,12 @@ module Foobara
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def option_set
|
64
|
-
# TODO: this feels wrong to pass self here...
|
65
65
|
@option_set ||= OptionSet.new
|
66
66
|
end
|
67
67
|
|
68
68
|
def attribute_to_option(
|
69
69
|
attribute_name = nil,
|
70
|
+
always_prefix_inputs:,
|
70
71
|
attribute_type: inputs_type,
|
71
72
|
is_required: true,
|
72
73
|
default: nil,
|
@@ -77,7 +78,8 @@ module Foobara
|
|
77
78
|
attribute_type:,
|
78
79
|
prefix:,
|
79
80
|
is_required:,
|
80
|
-
default
|
81
|
+
default:,
|
82
|
+
always_prefix_inputs:
|
81
83
|
)
|
82
84
|
|
83
85
|
if options.is_a?(::Array)
|
@@ -79,7 +79,7 @@ module Foobara
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def inputs_parser_for(command_class = self.command_class)
|
82
|
-
InputsParser.new(command_class.inputs_type)
|
82
|
+
InputsParser.new(command_class.inputs_type, always_prefix_inputs: command_connector.always_prefix_inputs)
|
83
83
|
end
|
84
84
|
|
85
85
|
def globalish_parser
|
data/src/sh_cli_connector.rb
CHANGED
@@ -3,10 +3,18 @@ module Foobara
|
|
3
3
|
class AlreadyHasAConnectedCommand < StandardError; end
|
4
4
|
|
5
5
|
class ShCliConnector < CommandConnector
|
6
|
-
attr_accessor :program_name, :single_command_mode
|
7
|
-
|
8
|
-
def initialize(
|
6
|
+
attr_accessor :program_name, :single_command_mode, :always_prefix_inputs
|
7
|
+
|
8
|
+
def initialize(
|
9
|
+
*,
|
10
|
+
program_name: File.basename($PROGRAM_NAME),
|
11
|
+
single_command_mode: false,
|
12
|
+
always_prefix_inputs: false,
|
13
|
+
**,
|
14
|
+
&
|
15
|
+
)
|
9
16
|
self.program_name = program_name
|
17
|
+
self.always_prefix_inputs = always_prefix_inputs
|
10
18
|
|
11
19
|
connect_args = if single_command_mode
|
12
20
|
self.single_command_mode = true
|