Class: Hiiro
- Inherits:
-
Object
show all
- Defined in:
- lib/hiiro.rb,
lib/hiiro/db.rb,
lib/hiiro/git.rb,
lib/hiiro/bins.rb,
lib/hiiro/glob.rb,
lib/hiiro/link.rb,
lib/hiiro/tags.rb,
lib/hiiro/tmux.rb,
lib/hiiro/todo.rb,
lib/hiiro/paths.rb,
lib/hiiro/queue.rb,
lib/hiiro/rbenv.rb,
lib/hiiro/shell.rb,
lib/hiiro/tasks.rb,
lib/hiiro/branch.rb,
lib/hiiro/config.rb,
lib/hiiro/git/pr.rb,
lib/hiiro/effects.rb,
lib/hiiro/matcher.rb,
lib/hiiro/options.rb,
lib/hiiro/project.rb,
lib/hiiro/version.rb,
lib/hiiro/projects.rb,
lib/hiiro/registry.rb,
lib/hiiro/registry.rb,
lib/hiiro/reminder.rb,
lib/hiiro/app_files.rb,
lib/hiiro/check_run.rb,
lib/hiiro/fuzzyfind.rb,
lib/hiiro/pane_home.rb,
lib/hiiro/pinned_pr.rb,
lib/hiiro/tmux/pane.rb,
lib/hiiro/any_struct.rb,
lib/hiiro/app_record.rb,
lib/hiiro/assignment.rb,
lib/hiiro/background.rb,
lib/hiiro/git/branch.rb,
lib/hiiro/git/remote.rb,
lib/hiiro/input_file.rb,
lib/hiiro/invocation.rb,
lib/hiiro/pin_record.rb,
lib/hiiro/tmux/panes.rb,
lib/hiiro/runner_tool.rb,
lib/hiiro/task_colors.rb,
lib/hiiro/task_record.rb,
lib/hiiro/tmux/buffer.rb,
lib/hiiro/tmux/window.rb,
lib/hiiro/git/branches.rb,
lib/hiiro/git/worktree.rb,
lib/hiiro/notification.rb,
lib/hiiro/tmux/buffers.rb,
lib/hiiro/tmux/session.rb,
lib/hiiro/tmux/windows.rb,
lib/hiiro/git/worktrees.rb,
lib/hiiro/tmux/sessions.rb,
lib/hiiro/service_manager.rb,
lib/hiiro/pinned_pr_manager.rb
Defined Under Namespace
Modules: Background, DB, Effects, TaskColors, Tasks
Classes: AnyStruct, App, AppFiles, AppRecord, Args, Assignment, Bins, Branch, CheckRun, Config, Environment, FallbackTarget, Fuzzyfind, Git, Glob, InputFile, Invocation, InvocationResolution, Link, Matcher, Notification, Options, PaneHome, Paths, PinRecord, PinnedPRManager, PinnedPr, Project, Projects, PsProcess, Queue, Rbenv, RegistryEntry, Reminder, Result, RunnerTool, Runners, ServiceManager, Shell, SparseGroups, Tag, Tags, Task, TaskManager, TaskRecord, Tmux, TodoItem, TodoManager, Tree
Constant Summary
collapse
- WORK_DIR =
File.join(Dir.home, 'work')
- REPO_PATH =
File.join(WORK_DIR, '.bare')
- PrefixMatcher =
Backward compatibility alias
Matcher
- VERSION =
"0.1.349"
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.init(*oargs, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block) ⇒ Object
-
.load_env ⇒ Object
-
.options(&block) ⇒ Object
-
.run(*args, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block) ⇒ Object
Instance Method Summary
collapse
-
#add_cmd(*names, args: [], opts: [], &block) ⇒ Object
-
#add_default(**values, &handler) ⇒ Object
-
#add_flag(name, **kwargs) ⇒ Object
-
#add_option(name, **kwargs) ⇒ Object
-
#add_resolver(name, current = nil, &lookup) ⇒ Object
-
#add_subcommand(*names, opts: nil, **values, &handler) ⇒ Object
(also: #add_subcmd)
-
#attach_method(name, &block) ⇒ Object
-
#auto_tag_branch_with_task ⇒ Object
-
#auto_var_name(path, existing_vars) ⇒ Object
-
#build_location_vars(list) ⇒ Object
-
#consolidate_dirs(dirs, min_depth:) ⇒ Object
Recursively group directories under their common ancestor when that ancestor is deep enough to be a useful alias (>= min_depth components).
-
#default_subcommand ⇒ Object
-
#edit_files(*files, max_splits: 3) ⇒ Object
-
#editor ⇒ Object
-
#environment ⇒ Object
(also: #env)
-
#full_name ⇒ Object
-
#fuzzyfind(lines) ⇒ Object
-
#fuzzyfind_from_map(mapping) ⇒ Object
-
#get_value(name) ⇒ Object
-
#git ⇒ Object
-
#handle_result(result) ⇒ Object
-
#help(options = nil) ⇒ Object
-
#initialize(bin, *all_args, logging: false, tasks: false, task_scope: nil, **values) ⇒ Hiiro
constructor
-
#list_runners(list) ⇒ Object
-
#load_plugin(plugin_const) ⇒ Object
-
#load_plugins(*plugins) ⇒ Object
-
#log(message) ⇒ Object
-
#make_child(custom_subcmd = nil, custom_args = nil, **kwargs, &block) ⇒ Object
-
#md_input_file(content: nil, append: false, prefix: 'edit-') ⇒ Object
-
#open_config(file, dir: nil) ⇒ Object
-
#options ⇒ Object
-
#parsed_args ⇒ Object
-
#path_lca(a, b) ⇒ Object
-
#pins ⇒ Object
-
#queue ⇒ Object
-
#registry_pick(type = nil) ⇒ Object
Pick a registry entry by fuzzyfinder.
-
#resolve(name, ref = nil) ⇒ Object
-
#run ⇒ Object
-
#run_child(custom_subcmd = nil, custom_args = nil, **kwargs, &block) ⇒ Object
-
#run_subcommand(name, *args) ⇒ Object
(also: #run_subcmd)
-
#runnable? ⇒ Boolean
-
#runner ⇒ Object
-
#runners ⇒ Object
-
#shorten_location(loc, vars) ⇒ Object
-
#start_tmux_session(name, **opts) ⇒ Object
-
#subcommand_names ⇒ Object
-
#task_manager ⇒ Object
(also: #tm)
-
#tasks ⇒ Object
-
#tasks_enabled? ⇒ Boolean
-
#this ⇒ Object
-
#tmux_client ⇒ Object
-
#todo_manager ⇒ Object
-
#vim? ⇒ Boolean
-
#yaml_input_file(content: nil, append: false, prefix: 'edit-') ⇒ Object
Constructor Details
#initialize(bin, *all_args, logging: false, tasks: false, task_scope: nil, **values) ⇒ Hiiro
Returns a new instance of Hiiro.
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/hiiro.rb', line 156
def initialize(bin, *all_args, logging: false, tasks: false, task_scope: nil, **values)
@bin = bin
@bin_name = File.basename(bin)
@all_args = all_args
@subcmd, *@args = all_args @loaded_plugins = []
@logging = logging
@tasks_enabled = tasks
@task_scope = task_scope
@global_values = values
@full_command = [
bin_name,
*all_args,
].map(&:shellescape).join(' ')
end
|
Instance Attribute Details
#all_args ⇒ Object
Returns the value of attribute all_args.
148
149
150
|
# File 'lib/hiiro.rb', line 148
def all_args
@all_args
end
|
#args ⇒ Object
Returns the value of attribute args.
149
150
151
|
# File 'lib/hiiro.rb', line 149
def args
@args
end
|
#bin ⇒ Object
Returns the value of attribute bin.
148
149
150
|
# File 'lib/hiiro.rb', line 148
def bin
@bin
end
|
#bin_name ⇒ Object
Returns the value of attribute bin_name.
148
149
150
|
# File 'lib/hiiro.rb', line 148
def bin_name
@bin_name
end
|
#full_command ⇒ Object
Returns the value of attribute full_command.
148
149
150
|
# File 'lib/hiiro.rb', line 148
def full_command
@full_command
end
|
#global_values ⇒ Object
Returns the value of attribute global_values.
152
153
154
|
# File 'lib/hiiro.rb', line 152
def global_values
@global_values
end
|
#loaded_plugins ⇒ Object
Returns the value of attribute loaded_plugins.
150
151
152
|
# File 'lib/hiiro.rb', line 150
def loaded_plugins
@loaded_plugins
end
|
#logging ⇒ Object
Returns the value of attribute logging.
151
152
153
|
# File 'lib/hiiro.rb', line 151
def logging
@logging
end
|
#opts ⇒ Object
Returns the value of attribute opts.
154
155
156
|
# File 'lib/hiiro.rb', line 154
def opts
@opts
end
|
#subcmd ⇒ Object
Returns the value of attribute subcmd.
149
150
151
|
# File 'lib/hiiro.rb', line 149
def subcmd
@subcmd
end
|
#task_scope ⇒ Object
Returns the value of attribute task_scope.
153
154
155
|
# File 'lib/hiiro.rb', line 153
def task_scope
@task_scope
end
|
Class Method Details
.init(*oargs, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/hiiro.rb', line 67
def self.init(*oargs, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block)
load_env
Hiiro::DB.setup!
h_bin = values[:bin_name] || $0
h_args = oargs
h_args = ARGV if h_args.empty?
h_args = values[:args] if values.key?(:args)
begin
Hiiro::Invocation.record!(
bin: File.basename(h_bin),
subcmd: h_args.first,
args: h_args[1..]
)
rescue => e
puts " ... ERROR ... there shouldn't be any reason for this to fail...unless sqlite is broken"
binding.pry
end
new(h_bin, *h_args, logging: logging, tasks: tasks, task_scope: task_scope, **values).tap do |hiiro|
hiiro.load_plugins(plugins)
hiiro.add_subcommand(:pry) { |*args|
binding.pry
}
hiiro.add_subcmd(:edit, **values) { |*args|
hiiro.edit_files(hiiro.bin)
}
if hiiro.tasks_enabled?
hiiro.add_subcmd(:task) do |*args|
tm = TaskManager.new(hiiro, scope: :task)
Tasks.build_hiiro(hiiro, tm).run
end
hiiro.add_subcmd(:subtask) do |*args|
tm = TaskManager.new(hiiro, scope: :subtask)
Tasks.build_hiiro(hiiro, tm).run
end
end
if block
if block.arity == 1
block.call(hiiro)
else
hiiro.instance_eval(&block)
end
end
end
end
|
.load_env ⇒ Object
140
141
142
143
144
145
146
|
# File 'lib/hiiro.rb', line 140
def self.load_env
Config.plugin_files.each do |plugin_file|
require plugin_file
end
self
end
|
.options(&block) ⇒ Object
130
131
132
|
# File 'lib/hiiro.rb', line 130
def self.options(&block)
Options.setup(&block)
end
|
.run(*args, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block) ⇒ Object
134
135
136
137
138
|
# File 'lib/hiiro.rb', line 134
def self.run(*args, plugins: [], logging: false, tasks: false, task_scope: nil, **values, &block)
hiiro = init(*args, plugins:, logging:, tasks:, task_scope:, **values, &block)
hiiro.run
end
|
Instance Method Details
#add_cmd(*names, args: [], opts: [], &block) ⇒ Object
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
# File 'lib/hiiro.rb', line 357
def add_cmd(*names, args: [], opts: [], &block)
cmd_opts = options.select(opts)
wrapper = lambda do |*raw_args|
@opts = cmd_opts.parse(raw_args)
instance_eval(&block)
end
names.each do |name|
runners.add_subcommand(
name, wrapper,
subcmd_args: args,
subcmd_opts: cmd_opts,
**global_values
)
end
end
|
#add_default(**values, &handler) ⇒ Object
318
319
320
|
# File 'lib/hiiro.rb', line 318
def add_default(**values, &handler)
runners.add_default(handler, **global_values, **values)
end
|
#add_flag(name, **kwargs) ⇒ Object
337
338
339
|
# File 'lib/hiiro.rb', line 337
def add_flag(name, **kwargs)
options.flag(name, **kwargs)
end
|
#add_option(name, **kwargs) ⇒ Object
333
334
335
|
# File 'lib/hiiro.rb', line 333
def add_option(name, **kwargs)
options.option(name, **kwargs)
end
|
#add_resolver(name, current = nil, &lookup) ⇒ Object
341
342
343
344
|
# File 'lib/hiiro.rb', line 341
def add_resolver(name, current = nil, &lookup)
@resolvers ||= {}
@resolvers[name.to_sym] = { current:, lookup: }
end
|
#add_subcommand(*names, opts: nil, **values, &handler) ⇒ Object
Also known as:
add_subcmd
322
323
324
325
326
|
# File 'lib/hiiro.rb', line 322
def add_subcommand(*names, opts: nil, **values, &handler)
names.each do |name|
runners.add_subcommand(name, handler, opts: opts, **global_values, **values)
end
end
|
#attach_method(name, &block) ⇒ Object
394
395
396
|
# File 'lib/hiiro.rb', line 394
def attach_method(name, &block)
define_singleton_method(name.to_sym, &block)
end
|
#auto_tag_branch_with_task ⇒ Object
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
# File 'lib/hiiro.rb', line 290
def auto_tag_branch_with_task
task = environment.task
return unless task
branch = environment.tree&.branch
return if branch.nil? || branch.empty?
return if %w[master main].include?(branch)
tag_store = Tags.new(:branch)
return if tag_store.get(branch).include?(task.name)
tag_store.add(branch, task.name)
rescue
end
|
#auto_var_name(path, existing_vars) ⇒ Object
516
517
518
519
520
521
522
523
|
# File 'lib/hiiro.rb', line 516
def auto_var_name(path, existing_vars)
parts = path.delete_prefix('/').split('/')
(1..parts.length).each do |n|
candidate = parts.last(n).join('_').upcase.gsub(/[^A-Z0-9]/, '_').squeeze('_').delete_prefix('_').delete_suffix('_')
return candidate unless existing_vars.key?(candidate)
end
"DIR_#{existing_vars.length + 1}"
end
|
#build_location_vars(list) ⇒ Object
479
480
481
482
483
484
485
486
487
488
489
490
491
|
# File 'lib/hiiro.rb', line 479
def build_location_vars(list)
paths = list.map { |r| r.location }.compact.map { |loc| loc.sub(/:\d+$/, '') }
dirs = paths.map { |p| File.dirname(p) }.uniq
ancestors = consolidate_dirs(dirs, min_depth: 4)
vars = {}
ancestors.sort.each do |ancestor|
name = auto_var_name(ancestor, vars)
vars[name] = ancestor
end
vars
end
|
#consolidate_dirs(dirs, min_depth:) ⇒ Object
Recursively group directories under their common ancestor when that ancestor is deep enough to be a useful alias (>= min_depth components).
495
496
497
498
499
500
501
502
503
504
505
506
507
508
|
# File 'lib/hiiro.rb', line 495
def consolidate_dirs(dirs, min_depth:)
return dirs if dirs.length <= 1
lca = dirs.reduce { |a, b| path_lca(a, b) }
lca_depth = lca.delete_prefix('/').split('/').reject(&:empty?).length
if lca_depth >= min_depth
[lca]
else
lca_parts = lca.split('/')
subgroups = dirs.group_by { |d| d.split('/').first(lca_parts.length + 1).join('/') }
subgroups.flat_map { |_, group| consolidate_dirs(group, min_depth: min_depth) }.uniq
end
end
|
#default_subcommand ⇒ Object
555
556
557
558
559
560
561
|
# File 'lib/hiiro.rb', line 555
def default_subcommand
Runners::Subcommand.new(
bin_name,
:DEFAULT,
lambda { |*args| help; false },
)
end
|
#edit_files(*files, max_splits: 3) ⇒ Object
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/hiiro.rb', line 213
def edit_files(*files, max_splits: 3)
if editor.match?(/vim/i)
if files.count > max_splits.to_i
system(editor, '-O' + max_splits.to_i.to_s, *files)
else
system(editor, '-O', *files)
end
else
system(editor, *files)
end
end
|
#editor ⇒ Object
195
196
197
198
199
|
# File 'lib/hiiro.rb', line 195
def editor
editors = Bins.glob(%w[nvim vim vi]).find(&File.method(:executable?))
ENV['EDITOR'] || editors.first
end
|
#environment ⇒ Object
Also known as:
env
180
181
182
|
# File 'lib/hiiro.rb', line 180
def environment
@environment ||= Environment.current
end
|
#full_name ⇒ Object
380
381
382
|
# File 'lib/hiiro.rb', line 380
def full_name
runner&.full_name || [bin_name, subcmd].join(?-)
end
|
#fuzzyfind(lines) ⇒ Object
543
544
545
|
# File 'lib/hiiro.rb', line 543
def fuzzyfind(lines)
Fuzzyfind.select(lines)
end
|
#fuzzyfind_from_map(mapping) ⇒ Object
547
548
549
|
# File 'lib/hiiro.rb', line 547
def fuzzyfind_from_map(mapping)
Fuzzyfind.map_select(mapping)
end
|
#get_value(name) ⇒ Object
551
552
553
|
# File 'lib/hiiro.rb', line 551
def get_value(name)
runner&.values&.[](name)
end
|
#git ⇒ Object
390
391
392
|
# File 'lib/hiiro.rb', line 390
def git
@git ||= Git.new(self, Dir.pwd)
end
|
#handle_result(result) ⇒ Object
284
285
286
287
288
|
# File 'lib/hiiro.rb', line 284
def handle_result(result)
exit 0 if result.nil? || result
exit 1
end
|
#help(options = nil) ⇒ Object
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
|
# File 'lib/hiiro.rb', line 419
def help(options=nil)
ambiguous = runners.ambiguous_matches
puts "Current command: #{bin_name}!"
if ambiguous.any?
puts "Ambiguous subcommand #{subcmd.inspect}!"
puts
puts "Did you mean one of these?"
list_runners(ambiguous)
puts
else
puts "Subcommand required for #{bin_name}"
puts
puts "Possible subcommands:"
list_runners(runners.all_runners)
puts
end
global = @options
if global && global.definitions.any? { |k, _| k != :help }
puts "Options:"
puts global.help_text
puts
end
if options
puts "Options:"
puts options.help_text
puts
end
exit 1
end
|
#list_runners(list) ⇒ Object
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
# File 'lib/hiiro.rb', line 454
def list_runners(list)
sorted = list.sort_by(&:subcommand_name)
vars = build_location_vars(sorted)
vars.each { |var_name, path| puts "export #{var_name}=\"#{path}\"" }
puts if vars.any?
max_name = sorted.map { |r| r.subcommand_name.length }.max || 0
max_type = sorted.map { |r| r.type.to_s.length }.max || 0
params_with_opts = sorted.map do |r|
parts = [r.params_string, (r.respond_to?(:opts_hint) ? r.opts_hint : nil)]
parts.compact.reject(&:empty?).join(' ')
end
max_params = params_with_opts.map(&:length).max || 0
sorted.each_with_index do |r, i|
name = r.subcommand_name.ljust(max_name)
type = "(#{r.type})".ljust(max_type + 2)
params_col = params_with_opts[i].ljust(max_params)
location = shorten_location(r.location, vars)
puts " #{name} #{params_col} #{type} #{location}"
end
end
|
#load_plugin(plugin_const) ⇒ Object
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
# File 'lib/hiiro.rb', line 402
def load_plugin(plugin_const)
if plugin_const.is_a?(String) || plugin_const.is_a?(Symbol)
begin
plugin_const = Kernel.const_get(plugin_const.to_sym)
rescue => e
puts "unable to load plugin: #{plugin_const}"
puts "Error message: #{e.message}"
return
end
end
return if @loaded_plugins.include?(plugin_const)
plugin_const.load(self)
@loaded_plugins.push(plugin_const)
end
|
#load_plugins(*plugins) ⇒ Object
398
399
400
|
# File 'lib/hiiro.rb', line 398
def load_plugins(*plugins)
plugins.flatten.each { |plugin| load_plugin(plugin) }
end
|
#log(message) ⇒ Object
533
534
535
536
537
|
# File 'lib/hiiro.rb', line 533
def log(message)
return unless logging
puts "[Hiiro: #{bin_name} #{(runner&.subcommand_name || subcmd).inspect}]: #{message}"
end
|
#make_child(custom_subcmd = nil, custom_args = nil, **kwargs, &block) ⇒ Object
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# File 'lib/hiiro.rb', line 237
def make_child(custom_subcmd=nil, custom_args=nil, **kwargs, &block)
child_subcmd = custom_subcmd || subcmd
child_args = custom_args || args
child_bin_name = [bin, child_subcmd.to_s].join(?-)
parent_resolvers = @resolvers&.dup
wrapper = lambda do |h|
h.instance_variable_set(:@resolvers, parent_resolvers.dup) if parent_resolvers
block.arity == 1 ? block.call(h) : h.instance_eval(&block) if block
end
begin
Hiiro.init(bin_name: child_bin_name, args: child_args, **kwargs, &wrapper)
rescue => e
binding.pry
end
end
|
209
210
211
|
# File 'lib/hiiro.rb', line 209
def md_input_file(content: nil, append: false, prefix: 'edit-')
InputFile.md_file(hiiro: self, content:, append:, prefix:)
end
|
#open_config(file, dir: nil) ⇒ Object
225
226
227
|
# File 'lib/hiiro.rb', line 225
def open_config(file, dir: nil)
Hiiro::Config.open(file, dir: dir)
end
|
#options ⇒ Object
329
330
331
|
# File 'lib/hiiro.rb', line 329
def options
@options ||= Hiiro::Options.setup {}
end
|
#parsed_args ⇒ Object
539
540
541
|
# File 'lib/hiiro.rb', line 539
def parsed_args
i = Args.new(*args)
end
|
#path_lca(a, b) ⇒ Object
510
511
512
513
514
|
# File 'lib/hiiro.rb', line 510
def path_lca(a, b)
a_parts = a.split('/')
b_parts = b.split('/')
a_parts.zip(b_parts).take_while { |x, y| x == y }.map(&:first).join('/')
end
|
#pins ⇒ Object
388
|
# File 'lib/hiiro.rb', line 388
def pins = @pins ||= Pin.new(self)
|
#queue ⇒ Object
265
266
267
|
# File 'lib/hiiro.rb', line 265
def queue
@queue ||= Queue.current
end
|
#registry_pick(type = nil) ⇒ Object
Pick a registry entry by fuzzyfinder. Returns the canonical name string, or nil. Usage inside a subcommand block:
task = opts.task || registry_pick('isc_task')
129
130
131
132
133
134
135
136
|
# File 'lib/hiiro/registry.rb', line 129
def registry_pick(type = nil)
lines = Hiiro::RegistryEntry.fuzzy_lines(type: type)
return nil if lines.empty?
chosen = fuzzyfind(lines)
return nil unless chosen
chosen.strip.split(/\s{2,}/)[2]
end
|
#resolve(name, ref = nil) ⇒ Object
346
347
348
349
350
351
352
353
354
355
|
# File 'lib/hiiro.rb', line 346
def resolve(name, ref = nil)
@resolvers ||= {}
r = @resolvers[name.to_sym] or raise "No resolver registered for :#{name}"
if ref.nil?
c = r[:current]
c.respond_to?(:call) ? c.call : c
else
r[:lookup]&.call(ref)
end
end
|
#run ⇒ Object
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
# File 'lib/hiiro.rb', line 269
def run
auto_tag_branch_with_task if tasks_enabled?
run_args = runners.using_default? ? [subcmd, *args].compact : args
result = runner.run(*run_args)
handle_result(result)
exit 1
rescue => e
puts "ERROR: #{e.message}"
puts e.backtrace
exit 1
end
|
#run_child(custom_subcmd = nil, custom_args = nil, **kwargs, &block) ⇒ Object
257
258
259
|
# File 'lib/hiiro.rb', line 257
def run_child(custom_subcmd=nil, custom_args=nil, **kwargs, &block)
make_child(custom_subcmd, custom_args, **kwargs, &block).run
end
|
#run_subcommand(name, *args) ⇒ Object
Also known as:
run_subcmd
375
376
377
|
# File 'lib/hiiro.rb', line 375
def run_subcommand(name, *args)
runners.run_subcommand(name, *args)
end
|
#runnable? ⇒ Boolean
306
307
308
|
# File 'lib/hiiro.rb', line 306
def runnable?
runner
end
|
#runner ⇒ Object
310
311
312
|
# File 'lib/hiiro.rb', line 310
def runner
runners.runner || runners.default_subcommand
end
|
#runners ⇒ Object
314
315
316
|
# File 'lib/hiiro.rb', line 314
def runners
@runners ||= Runners.new(self)
end
|
#shorten_location(loc, vars) ⇒ Object
525
526
527
528
529
530
531
|
# File 'lib/hiiro.rb', line 525
def shorten_location(loc, vars)
return loc if loc.nil?
vars.sort_by { |_, path| -path.length }.each do |var_name, path|
return loc.sub(path, "$#{var_name}") if loc.start_with?(path + '/') || loc == path
end
loc
end
|
#start_tmux_session(name, **opts) ⇒ Object
233
234
235
|
# File 'lib/hiiro.rb', line 233
def start_tmux_session(name, **opts)
tmux_client.open_session(name, **opts)
end
|
#subcommand_names ⇒ Object
384
385
386
|
# File 'lib/hiiro.rb', line 384
def subcommand_names
runners.subcommand_names
end
|
#task_manager ⇒ Object
Also known as:
tm
185
186
187
188
|
# File 'lib/hiiro.rb', line 185
def task_manager
return nil unless tasks_enabled?
@task_manager ||= TaskManager.new(self, scope: task_scope || :task)
end
|
#tasks ⇒ Object
191
192
193
|
# File 'lib/hiiro.rb', line 191
def tasks
task_manager&.tasks
end
|
#tasks_enabled? ⇒ Boolean
176
177
178
|
# File 'lib/hiiro.rb', line 176
def tasks_enabled?
@tasks_enabled
end
|
#this ⇒ Object
172
173
174
|
# File 'lib/hiiro.rb', line 172
def this
self
end
|
#tmux_client ⇒ Object
229
230
231
|
# File 'lib/hiiro.rb', line 229
def tmux_client
@tmux_client ||= Tmux.client!(self)
end
|
#todo_manager ⇒ Object
261
262
263
|
# File 'lib/hiiro.rb', line 261
def todo_manager
@todo_manager ||= TodoManager.new
end
|
#vim? ⇒ Boolean
201
202
203
|
# File 'lib/hiiro.rb', line 201
def vim?
editor.to_s.match?(/vim/i)
end
|
205
206
207
|
# File 'lib/hiiro.rb', line 205
def yaml_input_file(content: nil, append: false, prefix: 'edit-')
InputFile.yaml_file(hiiro: self, content:, append:, prefix:)
end
|