foobara-sh-cli-connector 0.0.1 → 0.0.2
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/request.rb +39 -11
- data/src/sh_cli_connector.rb +23 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b1018788f796d0bfc6ae3756d69ad14784d53f5e71a8a9858fe7b6911c79b9b
|
4
|
+
data.tar.gz: a629294b8364e4ba86fa1031f52e11266c835e2cfb371ecc479082d8f832afd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 983515e65dcdbdc13c2a63c64fda3524bfc383275b80a7a3950f94acd84cd84bb52a2e2e073b688fc6410f3e6d5f7f11d7fae843b7503c32e7935872c4cd8ca8
|
7
|
+
data.tar.gz: 186305f0c99bc81f8093ca8cb987defe85afd879a29ec9eb653804e96498301b02a2e59cc388512f742d7363c103bbd958b6dca02d0ba48ac9f78f67fe59b1c0
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,8 @@ module Foobara
|
|
5
5
|
|
6
6
|
class Request < CommandConnectors::Request
|
7
7
|
attr_accessor :argv,
|
8
|
+
:single_command_mode,
|
9
|
+
:command,
|
8
10
|
:globalish_options,
|
9
11
|
:inputs_argv,
|
10
12
|
:action,
|
@@ -15,7 +17,8 @@ module Foobara
|
|
15
17
|
:stderr,
|
16
18
|
:exit
|
17
19
|
|
18
|
-
def initialize(argv, exit: true, stdout: $stdout, stderr: $stderr, stdin: $stdin)
|
20
|
+
def initialize(argv, command:, exit: true, stdout: $stdout, stderr: $stderr, stdin: $stdin)
|
21
|
+
self.command = command
|
19
22
|
self.argv = argv
|
20
23
|
self.exit = exit
|
21
24
|
self.stdin = stdin
|
@@ -31,6 +34,10 @@ module Foobara
|
|
31
34
|
super()
|
32
35
|
end
|
33
36
|
|
37
|
+
def single_command_mode?
|
38
|
+
!!command
|
39
|
+
end
|
40
|
+
|
34
41
|
def input_serializer
|
35
42
|
@input_serializer ||= begin
|
36
43
|
input_format = globalish_options[:input_format]
|
@@ -86,6 +93,37 @@ module Foobara
|
|
86
93
|
private
|
87
94
|
|
88
95
|
def parse!
|
96
|
+
if single_command_mode?
|
97
|
+
parse_single_command!
|
98
|
+
else
|
99
|
+
parse_multi_command!
|
100
|
+
end
|
101
|
+
|
102
|
+
if action == "help"
|
103
|
+
globalish_options[:output_format] = "noop"
|
104
|
+
elsif action == "list"
|
105
|
+
globalish_options[:output_format] = "cli_tabular"
|
106
|
+
end
|
107
|
+
|
108
|
+
validate_parse_result!
|
109
|
+
|
110
|
+
set_serializers
|
111
|
+
end
|
112
|
+
|
113
|
+
def parse_single_command!
|
114
|
+
self.globalish_options = {}
|
115
|
+
|
116
|
+
if argv == ["--help"]
|
117
|
+
self.action = "help"
|
118
|
+
else
|
119
|
+
self.action = "run"
|
120
|
+
# TODO: needs to be the only registered command
|
121
|
+
self.argument = command
|
122
|
+
self.inputs_argv = argv
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def parse_multi_command!
|
89
127
|
if argv.empty?
|
90
128
|
self.action = "help"
|
91
129
|
self.globalish_options = {}
|
@@ -103,16 +141,6 @@ module Foobara
|
|
103
141
|
self.action_options = result.parsed
|
104
142
|
self.inputs_argv = result.remainder
|
105
143
|
end
|
106
|
-
|
107
|
-
if action == "help"
|
108
|
-
globalish_options[:output_format] = "noop"
|
109
|
-
elsif action == "list"
|
110
|
-
globalish_options[:output_format] = "cli_tabular"
|
111
|
-
end
|
112
|
-
|
113
|
-
validate_parse_result!
|
114
|
-
|
115
|
-
set_serializers
|
116
144
|
end
|
117
145
|
|
118
146
|
def validate_parse_result!
|
data/src/sh_cli_connector.rb
CHANGED
@@ -1,15 +1,36 @@
|
|
1
1
|
module Foobara
|
2
2
|
module CommandConnectors
|
3
|
+
class AlreadyHasAConnectedCommand < StandardError; end
|
4
|
+
|
3
5
|
class ShCliConnector < CommandConnector
|
4
|
-
attr_accessor :program_name
|
6
|
+
attr_accessor :program_name, :single_command_mode
|
5
7
|
|
6
|
-
def initialize(*, program_name: File.basename($PROGRAM_NAME), **, &)
|
8
|
+
def initialize(*, program_name: File.basename($PROGRAM_NAME), single_command_mode: false, **, &)
|
7
9
|
self.program_name = program_name
|
10
|
+
self.single_command_mode = single_command_mode
|
8
11
|
super(*, **, &)
|
9
12
|
|
10
13
|
# add_default_inputs_transformer ModelsToAttributesInputsTransformer
|
11
14
|
end
|
12
15
|
|
16
|
+
def connect(...)
|
17
|
+
super.tap do
|
18
|
+
if single_command_mode
|
19
|
+
if command_registry.size > 1
|
20
|
+
raise AlreadyHasAConnectedCommand, "Can't have more than one command in single command mode"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_request(*, **, &)
|
27
|
+
command = if single_command_mode
|
28
|
+
command_registry.foobara_all_command.first
|
29
|
+
end
|
30
|
+
|
31
|
+
self.class::Request.new(*, **, command:, &)
|
32
|
+
end
|
33
|
+
|
13
34
|
# TODO: this needs a better name... it's doing more than building.
|
14
35
|
def build_response(request)
|
15
36
|
response = super
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foobara-sh-cli-connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foobara
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- azimux@gmail.com
|
30
30
|
executables: []
|
@@ -59,7 +59,7 @@ metadata:
|
|
59
59
|
source_code_uri: https://github.com/foobara/sh-cli-connector
|
60
60
|
changelog_uri: https://github.com/foobara/sh-cli-connector/blob/main/CHANGELOG.md
|
61
61
|
rubygems_mfa_required: 'true'
|
62
|
-
post_install_message:
|
62
|
+
post_install_message:
|
63
63
|
rdoc_options: []
|
64
64
|
require_paths:
|
65
65
|
- lib
|
@@ -74,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
78
|
-
signing_key:
|
77
|
+
rubygems_version: 3.5.18
|
78
|
+
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Command-line connector for Foobara
|
81
81
|
test_files: []
|