foobara-sh-cli-connector 0.0.1 → 0.0.3
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 +8 -0
- data/src/sh_cli_connector/commands/help.rb +35 -16
- 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: 49472f1f26b8949b20ca528c5c31222114081776021ae2136f4ce869192c53df
|
4
|
+
data.tar.gz: c663144dbd5aa9398d86d2d52593485e3bece7bdd10f18fbec1e3a4bb5c3e18d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b6cb7dbb901da3888895fc2b01b036c9e3bfe10bc295d4adaed6fcf76748d3223b94933d9f71785cfb5766b0fd0788734076d2c36749117a7cea022ebbc1d94
|
7
|
+
data.tar.gz: da9ef8d6866ae4eaa8422932186fd061a1da733983664104629c959b198d136cff80e9488f804a59c54942629beb65919858ce4114a31fbcff47596ac7ca37c9
|
data/CHANGELOG.md
CHANGED
@@ -12,21 +12,34 @@ module Foobara
|
|
12
12
|
def execute
|
13
13
|
print_usage
|
14
14
|
|
15
|
-
if
|
16
|
-
|
17
|
-
|
18
|
-
print_command_input_options
|
19
|
-
end
|
15
|
+
if single_command_mode?
|
16
|
+
print_command_description
|
17
|
+
print_command_input_options
|
20
18
|
else
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
if valid_argument?
|
20
|
+
if argument_is_command?
|
21
|
+
print_command_description
|
22
|
+
print_command_input_options
|
23
|
+
end
|
24
|
+
else
|
25
|
+
print_available_actions
|
26
|
+
print_available_commands
|
27
|
+
end
|
24
28
|
|
25
|
-
|
29
|
+
print_global_options
|
30
|
+
end
|
26
31
|
|
27
32
|
output_string
|
28
33
|
end
|
29
34
|
|
35
|
+
def single_command_mode?
|
36
|
+
command_connector.single_command_mode
|
37
|
+
end
|
38
|
+
|
39
|
+
def command_connector
|
40
|
+
request.command_connector
|
41
|
+
end
|
42
|
+
|
30
43
|
def print_usage
|
31
44
|
if argument
|
32
45
|
if valid_argument?
|
@@ -48,7 +61,13 @@ module Foobara
|
|
48
61
|
end
|
49
62
|
|
50
63
|
def print_usage_without_argument
|
51
|
-
|
64
|
+
usage = if single_command_mode?
|
65
|
+
"[INPUTS]"
|
66
|
+
else
|
67
|
+
"[GLOBAL_OPTIONS] [ACTION] [COMMAND_OR_TYPE] [COMMAND_INPUTS]"
|
68
|
+
end
|
69
|
+
|
70
|
+
output.puts "Usage: #{program_name} #{usage}"
|
52
71
|
end
|
53
72
|
|
54
73
|
def print_usage_for_argument
|
@@ -78,10 +97,6 @@ module Foobara
|
|
78
97
|
command_connector.program_name
|
79
98
|
end
|
80
99
|
|
81
|
-
def command_connector
|
82
|
-
request.command_connector
|
83
|
-
end
|
84
|
-
|
85
100
|
def command_registry
|
86
101
|
command_connector.command_registry
|
87
102
|
end
|
@@ -101,7 +116,11 @@ module Foobara
|
|
101
116
|
def command_class
|
102
117
|
return @command_class if defined?(@command_class)
|
103
118
|
|
104
|
-
@command_class =
|
119
|
+
@command_class = if single_command_mode?
|
120
|
+
command_registry.all_transformed_command_classes.first
|
121
|
+
else
|
122
|
+
argument && command_registry.transformed_command_from_name(argument)
|
123
|
+
end
|
105
124
|
end
|
106
125
|
|
107
126
|
def argument_is_action?
|
@@ -156,7 +175,7 @@ module Foobara
|
|
156
175
|
|
157
176
|
def print_command_input_options
|
158
177
|
output.puts
|
159
|
-
output.puts "Command inputs:"
|
178
|
+
output.puts single_command_mode? ? "Inputs:" : "Command inputs:"
|
160
179
|
output.puts
|
161
180
|
output.puts request.inputs_parser_for(command_class).parser.summarize
|
162
181
|
end
|
@@ -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.3
|
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-13 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: []
|