foobara-sh-cli-connector 0.0.10 → 0.0.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b947cee595a654d406a661d30431063454d79f6c6af716e98be1ac6dc710884c
4
- data.tar.gz: b5738adbb22bde8105ba81a5e72672c4de819cb7db897b01e920ac51be3c9329
3
+ metadata.gz: baee3b1690dc7108efe1763f106088b5c60ec44bee67f9e5e973af806dc23dcb
4
+ data.tar.gz: ff4692056eed0949ef1c4f1b0ece541e3c5805ed9afd1fb282feb35727c48780
5
5
  SHA512:
6
- metadata.gz: c8c99d022c86899d8cbdb0d026a6db3073d3ec85e9cae677a1a6ec34e1233897e7688992b6e7ab138442f8ba2670a5398771e5b3f23f726e5f1095ab226135a3
7
- data.tar.gz: ed5e06abe72c37b470ed73946411c368076d7e6dc9cdcd99e38fb49adca133ed5023a2be71414019e19839759e0ede6366a51020f6481848c3c98e98b67916fa
6
+ metadata.gz: c45bc3cb9f0d47d3ec1dce2cc6fb7ce34712905f9f2c8895d03c56ba5e3bc1a285bc5f325740d17c5d7f6403e17892836b71829f0d065e1c4e0d124823e5c97d
7
+ data.tar.gz: 7de22a9ff9f3f780b08eb8cb4587204232d7d5e8bd00ccedfead314d737401acd31a51c26a13bc68ad518ec336003e1332aabf2ff40040b336ed70b897fb555a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [0.0.13] - 2025-03-28
2
+
3
+ - Handle recent #request_to_response refactor
4
+
5
+ ## [0.0.12] - 2025-03-06
6
+
7
+ - Allow passing a command or connect args to single_command_mode:
8
+
9
+ ## [0.0.11] - 2025-01-07
10
+
11
+ - Bump Ruby to 3.4.1
12
+
1
13
  ## [0.0.10] - 2024-12-09
2
14
 
3
15
  - Do not explode when serializing an empty table
@@ -11,6 +11,8 @@ module Foobara
11
11
 
12
12
  def validate!
13
13
  unless remainder.empty?
14
+ # TODO: let's invert the order for single command mode: parse inputs first, then global from remainder,
15
+ # and then raise if there's anything left
14
16
  raise ParseError, "Unexpected argument: #{remainder.first}"
15
17
  end
16
18
  end
@@ -120,6 +120,7 @@ module Foobara
120
120
  # TODO: needs to be the only registered command
121
121
  self.argument = command
122
122
  self.inputs_argv = argv
123
+ self.command_class = command.command_class
123
124
  end
124
125
  end
125
126
 
@@ -144,9 +145,9 @@ module Foobara
144
145
  end
145
146
 
146
147
  def validate_parse_result!
147
- if action == "help" || action == "list"
148
+ if %w[help list].include?(action)
148
149
  # This gives some leniency around where the global options are when there's no command
149
- result = globalish_parser.parse(inputs_argv)
150
+ result = globalish_parser.parse(inputs_argv)
150
151
 
151
152
  if result.remainder.any?
152
153
  # :nocov:
@@ -172,8 +172,8 @@ module Foobara
172
172
 
173
173
  parts_size = parts.size
174
174
 
175
- parts.each.with_index do |rows_worth, index|
176
- rows_worth << "-" unless index == parts_size - 1
175
+ parts.each.with_index do |rows_worth, inner_index|
176
+ rows_worth << "-" unless inner_index == parts_size - 1
177
177
  cell << rows_worth
178
178
  end
179
179
  else
@@ -7,10 +7,22 @@ module Foobara
7
7
 
8
8
  def initialize(*, program_name: File.basename($PROGRAM_NAME), single_command_mode: false, **, &)
9
9
  self.program_name = program_name
10
- self.single_command_mode = single_command_mode
10
+
11
+ connect_args = if single_command_mode
12
+ self.single_command_mode = true
13
+
14
+ if single_command_mode.is_a?(::Array)
15
+ single_command_mode
16
+ elsif single_command_mode.is_a?(::Class) && single_command_mode < Foobara::Command
17
+ [single_command_mode]
18
+ end
19
+ end
20
+
11
21
  super(*, **, &)
12
22
 
13
- # add_default_inputs_transformer ModelsToAttributesInputsTransformer
23
+ if connect_args
24
+ connect(*connect_args)
25
+ end
14
26
  end
15
27
 
16
28
  def connect(...)
@@ -53,48 +65,54 @@ module Foobara
53
65
  nil
54
66
  end
55
67
 
56
- def request_to_response(request)
57
- if request.error
58
- case request.error
59
- when ParseError, CommandConnector::NotFoundError
60
- return Response.new(status: 6, body: request.error.message, request:)
61
- else
62
- # :nocov:
63
- raise "Not sure how to handle error: #{request.error}"
64
- # :nocov:
65
- end
66
- end
68
+ def set_response_status(response)
69
+ request = response.request
70
+
71
+ response.status = if request.error
72
+ 6
73
+ elsif request.success?
74
+ 0
75
+ else
76
+ errors = request.error_collection.error_array
77
+ error = errors.first
78
+
79
+ case error
80
+ when CommandConnector::NotFoundError, Foobara::Entity::NotFoundError
81
+ # TODO: we should not be coupled to Entities here...
82
+ # :nocov:
83
+ 2
84
+ # :nocov:
85
+ when CommandConnector::UnauthenticatedError
86
+ # :nocov:
87
+ 3
88
+ # :nocov:
89
+ when CommandConnector::NotAllowedError
90
+ # :nocov:
91
+ 4
92
+ # :nocov:
93
+ when CommandConnector::UnknownError
94
+ # :nocov:
95
+ 5
96
+ # :nocov:
97
+ end || 1
98
+ end
99
+ end
67
100
 
68
- body = request.response_body
69
-
70
- status = if request.success?
71
- 0
72
- else
73
- errors = request.error_collection.error_array
74
- error = errors.first
75
-
76
- case error
77
- when CommandConnector::NotFoundError, Foobara::Entity::NotFoundError
78
- # TODO: we should not be coupled to Entities here...
79
- # :nocov:
80
- 2
81
- # :nocov:
82
- when CommandConnector::UnauthenticatedError
83
- # :nocov:
84
- 3
85
- # :nocov:
86
- when CommandConnector::NotAllowedError
87
- # :nocov:
88
- 4
89
- # :nocov:
90
- when CommandConnector::UnknownError
91
- # :nocov:
92
- 5
93
- # :nocov:
94
- end || 1
95
- end
96
-
97
- Response.new(status:, body:, request:)
101
+ def set_response_body(response)
102
+ request = response.request
103
+
104
+ response.body = if request.error
105
+ case request.error
106
+ when ParseError, CommandConnector::NotFoundError
107
+ request.error.message
108
+ else
109
+ # :nocov:
110
+ raise "Not sure how to handle error: #{request.error}"
111
+ # :nocov:
112
+ end
113
+ else
114
+ request.response_body
115
+ end
98
116
  end
99
117
  end
100
118
  end
metadata CHANGED
@@ -1,30 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-sh-cli-connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-09 00:00:00.000000000 Z
10
+ date: 2025-03-28 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: foobara
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ">="
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: 0.0.88
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ">="
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '0'
27
- description:
25
+ version: 0.0.88
28
26
  email:
29
27
  - azimux@gmail.com
30
28
  executables: []
@@ -64,7 +62,6 @@ metadata:
64
62
  source_code_uri: https://github.com/foobara/sh-cli-connector
65
63
  changelog_uri: https://github.com/foobara/sh-cli-connector/blob/main/CHANGELOG.md
66
64
  rubygems_mfa_required: 'true'
67
- post_install_message:
68
65
  rdoc_options: []
69
66
  require_paths:
70
67
  - lib
@@ -72,15 +69,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
69
  requirements:
73
70
  - - ">="
74
71
  - !ruby/object:Gem::Version
75
- version: 3.2.2
72
+ version: 3.4.0
76
73
  required_rubygems_version: !ruby/object:Gem::Requirement
77
74
  requirements:
78
75
  - - ">="
79
76
  - !ruby/object:Gem::Version
80
77
  version: '0'
81
78
  requirements: []
82
- rubygems_version: 3.5.23
83
- signing_key:
79
+ rubygems_version: 3.6.6
84
80
  specification_version: 4
85
81
  summary: Command-line connector for Foobara
86
82
  test_files: []