hiiro 0.1.151 → 0.1.153

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: 98bf6f648f72277fb219044bd6f5a5e0c1320c21d122e8478cc4e6d6f7000a4b
4
- data.tar.gz: 6308aa3432b0cf8e9f2fc3ca4fc66fb9075902fb3c421fad4d2dbd03f2105418
3
+ metadata.gz: b270bade909acb9e7805983022b54951c14048c9964f758a011448400cc8e492
4
+ data.tar.gz: 5045f0d977f5113886e6c35d8288a5eb9ca697a24f529a097ff9f61ceda70e62
5
5
  SHA512:
6
- metadata.gz: 268febf76230f6cb10ac9b492bc7c37fb34d48764b43d912dc430ae66f9b29cae1190c58109fa93d2935b4145a1e75685f6a8a1f4345e0ff53a40e70326301bc
7
- data.tar.gz: dbf74be661003f9b67e878c9284d2b4a6ef4d20712226e6021023b5e2e7d8352bb671c8a86e184367fb0bad38301a4c589a6254c8d2ba2660d972a178d715feb
6
+ metadata.gz: 9ea8d52d648ab2cf4d79d7a35a1877a53e7bff26fab0ece31d0d4b3b46172b04aeadef115395bd154f60bfc418acdfd8b0b7bdca20cb6affc499751ba8bb8687
7
+ data.tar.gz: 2ff7f43419014b05dab1e12c15200eb612c81966bc9611b47b88f6127aad8ceafd423514a70f1f876600d590be41646ca675fc15e8d78a8c70a43e2c92498112
@@ -166,6 +166,44 @@ class Hiiro
166
166
  load_state
167
167
  end
168
168
 
169
+ def reset(name)
170
+ svc = find_service(name)
171
+ unless svc
172
+ puts "Service '#{name}' not found"
173
+ return false
174
+ end
175
+
176
+ svc_name = svc[:name]
177
+ state = load_state
178
+ unless state.key?(svc_name)
179
+ puts "Service '#{svc_name}' is not in running state"
180
+ return false
181
+ end
182
+
183
+ state.delete(svc_name)
184
+ save_state(state)
185
+ puts "Reset service '#{svc_name}' (cleared from running state)"
186
+ true
187
+ end
188
+
189
+ def clean
190
+ state = load_state
191
+ return puts("No running services to clean") if state.empty?
192
+
193
+ stale = state.select { |_, info| stale_pane?(info['tmux_pane']) }
194
+ if stale.empty?
195
+ puts "All running services have live panes"
196
+ return false
197
+ end
198
+
199
+ stale.each do |svc_name, _|
200
+ state.delete(svc_name)
201
+ puts "Cleaned stale service '#{svc_name}'"
202
+ end
203
+ save_state(state)
204
+ true
205
+ end
206
+
169
207
  def start(name, tmux_info: {}, task_info: {}, variation_overrides: {}, skip_env: false, skip_window_creation: false)
170
208
  svc = find_service(name)
171
209
  unless svc
@@ -205,12 +243,13 @@ class Hiiro
205
243
  return false
206
244
  end
207
245
 
208
- # Coerce start command to array
209
246
  start_cmds = Array(start_cmd)
210
-
211
247
  base_dir = svc[:base_dir]
212
248
  session = tmux_info[:session] || current_tmux_session
213
249
 
250
+ # Write start commands to an executable tempfile
251
+ script = write_start_script(svc_name, start_cmds)
252
+
214
253
  if session && !skip_window_creation
215
254
  # Create a new tmux window for this service
216
255
  window_target = create_tmux_window(session, svc_name, base_dir || Dir.pwd)
@@ -225,16 +264,11 @@ class Hiiro
225
264
  end
226
265
 
227
266
  if pane_id
228
- # Send each start command to the pane
229
- combined_cmd = start_cmds.join(' && ')
230
- system('tmux', 'send-keys', '-t', pane_id, combined_cmd, 'Enter')
267
+ system('tmux', 'send-keys', '-t', pane_id, script, 'Enter')
268
+ elsif base_dir
269
+ system("cd #{base_dir} && #{script} &")
231
270
  else
232
- combined_cmd = start_cmds.join(' && ')
233
- if base_dir
234
- system("cd #{base_dir} && #{combined_cmd} &")
235
- else
236
- system("#{combined_cmd} &")
237
- end
271
+ system("#{script} &")
238
272
  end
239
273
 
240
274
  # Record state
@@ -437,8 +471,13 @@ class Hiiro
437
471
 
438
472
  h.add_subcmd(:start) do |svc_name=nil, *extra_args|
439
473
  unless svc_name
440
- puts "Usage: service start <name> [--use VAR=variation ...]"
441
- next
474
+ all = sm.services.keys
475
+ if all.empty?
476
+ puts "No services configured"
477
+ next
478
+ end
479
+ svc_name = h.fuzzyfind(all)
480
+ next unless svc_name
442
481
  end
443
482
 
444
483
  # Parse --use flags from extra_args
@@ -481,17 +520,45 @@ class Hiiro
481
520
 
482
521
  h.add_subcmd(:stop) do |svc_name=nil|
483
522
  unless svc_name
484
- puts "Usage: service stop <name>"
485
- next
523
+ running = sm.running_services.keys
524
+ if running.empty?
525
+ puts "No running services"
526
+ next
527
+ end
528
+ svc_name = h.fuzzyfind(running)
529
+ next unless svc_name
486
530
  end
487
531
 
488
532
  sm.stop(svc_name)
489
533
  end
490
534
 
535
+ h.add_subcmd(:reset) do |svc_name=nil|
536
+ unless svc_name
537
+ running = sm.running_services.keys
538
+ if running.empty?
539
+ puts "No running services"
540
+ next
541
+ end
542
+ svc_name = h.fuzzyfind(running)
543
+ next unless svc_name
544
+ end
545
+
546
+ sm.reset(svc_name)
547
+ end
548
+
549
+ h.add_subcmd(:clean) do
550
+ sm.clean
551
+ end
552
+
491
553
  h.add_subcmd(:attach) do |svc_name=nil|
492
554
  unless svc_name
493
- puts "Usage: service attach <name>"
494
- next
555
+ running = sm.running_services.keys
556
+ if running.empty?
557
+ puts "No running services"
558
+ next
559
+ end
560
+ svc_name = h.fuzzyfind(running)
561
+ next unless svc_name
495
562
  end
496
563
 
497
564
  sm.attach(svc_name)
@@ -541,8 +608,13 @@ class Hiiro
541
608
 
542
609
  h.add_subcmd(:status) do |svc_name=nil|
543
610
  unless svc_name
544
- puts "Usage: service status <name>"
545
- next
611
+ running = sm.running_services.keys
612
+ if running.empty?
613
+ puts "No running services"
614
+ next
615
+ end
616
+ svc_name = h.fuzzyfind(running)
617
+ next unless svc_name
546
618
  end
547
619
 
548
620
  sm.status(svc_name)
@@ -660,6 +732,24 @@ class Hiiro
660
732
 
661
733
  private
662
734
 
735
+ def stale_pane?(pane_id)
736
+ return true unless pane_id
737
+ !system('tmux', 'has-session', '-t', pane_id, [:out, :err] => '/dev/null')
738
+ end
739
+
740
+ def write_start_script(svc_name, cmds)
741
+ dir = File.join(STATE_DIR, 'scripts')
742
+ FileUtils.mkdir_p(dir)
743
+ path = File.join(dir, "#{svc_name}.sh")
744
+
745
+ lines = ["#!/usr/bin/env bash", "set -e"]
746
+ lines.concat(cmds)
747
+
748
+ File.write(path, lines.join("\n") + "\n")
749
+ File.chmod(0755, path)
750
+ path
751
+ end
752
+
663
753
  def current_tmux_session
664
754
  return nil unless ENV['TMUX']
665
755
  `tmux display-message -p '#S'`.chomp
data/lib/hiiro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Hiiro
2
- VERSION = "0.1.151"
2
+ VERSION = "0.1.153"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiiro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.151
4
+ version: 0.1.153
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota