gloo-cli 1.8 → 1.9

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/shell.rb +32 -12
  3. data/lib/shell_runner.rb +27 -9
  4. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c20054e5d495fde4abf0d067fd09015b02af2de350075834b2f58914f54be0d1
4
- data.tar.gz: e363c1996f92d4718b75ed1176ea640a4484efb08cc91737337f8fdd80e65ec0
3
+ metadata.gz: 16d9a2fde425817962361d58b380edd237a59dfa4d1eb5f207f60e99ec019c51
4
+ data.tar.gz: 6efaf972d566c21d6353e0da0cbb333b22726d27ebd39799d38281c8943e0c19
5
5
  SHA512:
6
- metadata.gz: 90750e252eb055d6378177d2b22cdaac0eb57c1171128f341c37f40b603f7e5231a11cbe4463b9bf145d8a2fecc37a929ef7dcad788cfeee06772ee089e4ab47
7
- data.tar.gz: 0d0ddc595fdd62f09ce591e7167df8542ee22eb3dbb97990ed5c3e556c99f52d360f935ae96489744feb906d02f1ba5e51ce32c44cc9d613c8f1722590edd1a9
6
+ metadata.gz: f979302be6f0c9d5a97d7bd2a7f9c1f77ba82033bb95ad2e3740bcf8d4ccb7ff6f7044eec02d5985cfa3bbcf321b9f768f2c11122b96fdde7960797d3c3fc309
7
+ data.tar.gz: 947e3b9edcfd87644751ab5fdba9248f149a19400069bd50e775b5fb45f1b57b15641bc701ea6764f532fa2ff25f9b20c928179ddec29510c88ebf73680488b9
data/lib/shell.rb CHANGED
@@ -16,6 +16,7 @@ class Shell < Gloo::Core::Obj
16
16
  ON_EMPTY_CMD = 'on_empty_command'.freeze
17
17
  BEFORE_ACTION = 'before_action'.freeze
18
18
  AFTER_ACTION = 'after_action'.freeze
19
+ WITH_COMMAND = 'with_command'.freeze
19
20
 
20
21
  #
21
22
  # The name of the object type.
@@ -89,17 +90,37 @@ class Shell < Gloo::Core::Obj
89
90
  return super + [ 'start', 'stop' ]
90
91
  end
91
92
 
92
- #
93
+ #
93
94
  # Get the shell runner or initialize it if it doesn't exist.
95
+ # In App mode, any CLI parameter(s) after the app path become the
96
+ # runner's single command (see ShellRunner#single_command?) rather
97
+ # than files for gloo to load - @engine.args keeps those out of
98
+ # @engine.args.files for exactly this reason.
94
99
  #
95
100
  def get_runner
96
- return @runner ||= ShellRunner.new( @engine, self )
101
+ set_with_command
102
+ return @runner ||= ShellRunner.new( @engine, self, command: @engine.args.command_tokens )
97
103
  end
98
-
104
+
105
+ #
106
+ # If the app was invoked with a supplied command, record it on a
107
+ # with_command child (creating it if the script hasn't declared one
108
+ # itself), so scripts can tell a one-shot run from an interactive
109
+ # session - even before the shell starts (e.g. to skip a banner or
110
+ # menu). Left untouched (and uncreated) when no command was given.
111
+ #
112
+ def set_with_command
113
+ tokens = @engine.args.command_tokens
114
+ return if tokens.empty?
115
+
116
+ o = find_child( WITH_COMMAND ) || @engine.factory.create_string( WITH_COMMAND, '', self )
117
+ o.set_value( tokens.join( ' ' ) )
118
+ end
119
+
99
120
  #
100
121
  # Start the shell.
101
- # If CLI args were passed, execute that command once and return.
102
- # Otherwise, enter the interactive REPL.
122
+ # If the app was invoked with extra command-line arguments, execute
123
+ # that one command and return. Otherwise, enter the interactive REPL.
103
124
  #
104
125
  def msg_start
105
126
  runner = get_runner
@@ -107,12 +128,7 @@ class Shell < Gloo::Core::Obj
107
128
  # add_test_commands
108
129
  add_quit_command
109
130
 
110
- cmd_tokens = @engine.args.files
111
- if cmd_tokens.any?
112
- runner.execute_once( cmd_tokens )
113
- else
114
- runner.start
115
- end
131
+ runner.start
116
132
  end
117
133
 
118
134
  #
@@ -237,7 +253,11 @@ class Shell < Gloo::Core::Obj
237
253
  "on_unknown_command (script) — Optional. Run when the input doesn't match any known command; if absent, a default \"Unknown command\" message is shown instead.",
238
254
  'on_empty_command (script) — Optional. Run when the user submits an empty line.',
239
255
  'before_action (script) — Optional. Run before every command executes.',
240
- 'after_action (script) — Optional. Run after every command executes.'
256
+ 'after_action (script) — Optional. Run after every command executes.',
257
+ 'with_command (string) — Not present by default. Set (and created if the ' \
258
+ 'script hasn\'t declared it) to the supplied command text whenever the app ' \
259
+ 'was invoked with extra command-line arguments - check for it to tell a ' \
260
+ 'one-shot run from an interactive session.'
241
261
  ],
242
262
  :messages => [
243
263
  'start — Start the shell. If the app was invoked with extra command-line arguments, execute that one command and return; otherwise enter the interactive REPL.',
data/lib/shell_runner.rb CHANGED
@@ -11,14 +11,18 @@ class ShellRunner
11
11
  DEFAULT_PROMPT = " -> "
12
12
  UNKNOWN_COMMAND = "Unknown command".freeze
13
13
 
14
- #
14
+ #
15
15
  # Initialize the shell runner
16
- #
16
+ #
17
17
  # @param obj [Object] The shell obj.
18
- #
19
- def initialize( engine, obj )
18
+ # @param opts [Hash] :command (Array<String>) - tokens for a single
19
+ # command to run once, instead of entering the interactive REPL -
20
+ # see #single_command?.
21
+ #
22
+ def initialize( engine, obj, opts = {} )
20
23
  @engine = engine
21
24
  @obj = obj
25
+ @command = opts[ :command ]
22
26
  @context = ShellContext.new
23
27
  @root = CommandNode.new( nil )
24
28
  end
@@ -27,12 +31,26 @@ class ShellRunner
27
31
  # ---------------------------------------------------------------------
28
32
  # Shell, control, start and stop
29
33
  # ---------------------------------------------------------------------
30
-
31
- #
32
- # Start the shell.
33
- #
34
+
35
+ #
36
+ # Were command tokens supplied at construction? When true, #start
37
+ # runs that one command via #execute_once and returns instead of
38
+ # entering the REPL.
39
+ #
40
+ def single_command?
41
+ return !( @command.nil? || @command.empty? )
42
+ end
43
+
44
+ #
45
+ # Start the shell: run the single supplied command and return,
46
+ # or enter the interactive REPL if none was supplied.
47
+ #
34
48
  def start
35
- repl
49
+ if single_command?
50
+ execute_once( @command )
51
+ else
52
+ repl
53
+ end
36
54
  end
37
55
 
38
56
  #
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloo-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.8'
4
+ version: '1.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Crane
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-09-14 00:00:00.000000000 Z
11
12
  dependencies: []
12
13
  description: Adds CLI support to Gloo.
13
14
  email:
@@ -35,6 +36,7 @@ licenses:
35
36
  metadata:
36
37
  gloo.type: core-library
37
38
  documentation_uri: https://github.com/ecrane/gloo
39
+ post_install_message:
38
40
  rdoc_options: []
39
41
  require_paths:
40
42
  - lib
@@ -49,7 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
51
  - !ruby/object:Gem::Version
50
52
  version: '0'
51
53
  requirements: []
52
- rubygems_version: 4.0.17
54
+ rubygems_version: 3.5.16
55
+ signing_key:
53
56
  specification_version: 4
54
57
  summary: Gloo core library. CLI support.
55
58
  test_files: []