Class: Tmuxinator::Cli
- Inherits:
-
Thor
- Object
- Thor
- Tmuxinator::Cli
show all
- Includes:
- Util
- Defined in:
- lib/tmuxinator/cli.rb
Constant Summary
collapse
- COMMANDS =
{
commands: "Lists commands available in tmuxinator",
completions: "Used for shell completion",
copy: %w{
Copy an existing project to a new project and
open it in your editor
}.join(" "),
debug: "Output the shell commands that are generated by tmuxinator",
delete: "Deletes given project",
doctor: "Look for problems in your configuration",
edit: "Alias of new",
implode: "Deletes all tmuxinator projects",
local: "Start a tmux session using ./.tmuxinator.y[a]ml",
list: "Lists all tmuxinator projects",
new: "Create a new project file and open it in your editor",
open: "Alias of new",
start: %w{
Start a tmux session using a project's name (with an optional [ALIAS]
for project reuse) or a path to a project config file (via the -p flag)
}.join(" "),
stop: "Stop a tmux session using a project's tmuxinator config",
stop_all: "Stop all tmux sessions which are using tmuxinator projects",
version: "Display installed tmuxinator version",
}.freeze
- THOR_COMMANDS =
For future reference: due to how tmuxinator currently consumes command-line arguments (see ::bootstrap, below), invocations of Thor’s base commands (i.e. ‘help’, etc) can be instead routed to #start (rather than to ::start). In order to prevent this, the THOR_COMMANDS and RESERVED_COMMANDS constants have been introduced. The former enumerates any/all Thor commands we want to insure get passed through to Thor.start. The latter is the superset of the Thor commands and any tmuxinator commands, defined in COMMANDS, above.
%w[-v help].freeze
- RESERVED_COMMANDS =
(COMMANDS.keys + THOR_COMMANDS).map(&:to_s).freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util
#current_session_name, #exit!, #yes_no
Class Method Details
.bootstrap(args = []) ⇒ Object
This method was defined as something of a workaround… Previously the conditional contained within was in the executable (i.e. bin/tmuxinator). It has been moved here so as to be testable. A couple of notes:
array or ARGV, not a varargs. Perhaps ::bootstrap should as well?
signature
453
454
455
456
457
458
459
460
461
462
463
|
# File 'lib/tmuxinator/cli.rb', line 453
def self.bootstrap(args = [])
name = args[0] || nil
if args.empty? && Tmuxinator::Config.local?
Tmuxinator::Cli.new.local
elsif name && !Tmuxinator::Cli::RESERVED_COMMANDS.include?(name) &&
Tmuxinator::Config.exist?(name: name)
Tmuxinator::Cli.start([:start, *args])
else
Tmuxinator::Cli.start(args)
end
end
|
.exit_on_failure? ⇒ Boolean
9
10
11
|
# File 'lib/tmuxinator/cli.rb', line 9
def self.exit_on_failure?
true
end
|
Instance Method Details
#commands(shell = nil) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/tmuxinator/cli.rb', line 56
def commands(shell = nil)
out = if shell == "zsh"
COMMANDS.map do |command, desc|
"#{command}:#{desc}"
end.join("\n")
else
COMMANDS.keys.join("\n")
end
say out
end
|
#completions(arg) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/tmuxinator/cli.rb', line 70
def completions(arg)
if %w(start stop edit open copy delete).include?(arg)
configs = Tmuxinator::Config.configs
say configs.join("\n")
end
end
|
#copy(existing, new) ⇒ Object
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/tmuxinator/cli.rb', line 357
def copy(existing, new)
existing_config_path = Tmuxinator::Config.project(existing)
new_config_path = Tmuxinator::Config.project(new)
exit!("Project #{existing} doesn't exist!") \
unless Tmuxinator::Config.exist?(name: existing)
new_exists = Tmuxinator::Config.exist?(name: new)
question = "#{new} already exists, would you like to overwrite it?"
if !new_exists || yes?(question, :red)
say "Overwriting #{new}" if Tmuxinator::Config.exist?(name: new)
FileUtils.copy_file(existing_config_path, new_config_path)
end
Kernel.system("$EDITOR #{new_config_path}")
end
|
#debug(name = nil, *args) ⇒ Object
345
346
347
348
349
350
351
|
# File 'lib/tmuxinator/cli.rb', line 345
def debug(name = nil, *args)
params = start_params(name, *args)
project = create_project(params)
say project.render
end
|
#delete(*projects) ⇒ Object
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
# File 'lib/tmuxinator/cli.rb', line 378
def delete(*projects)
projects.each do |project|
if Tmuxinator::Config.exist?(name: project)
config = Tmuxinator::Config.project(project)
if yes?("Are you sure you want to delete #{project}?(y/n)", :red)
FileUtils.rm(config)
say "Deleted #{project}"
end
else
say "#{project} does not exist!"
end
end
end
|
#doctor ⇒ Object
434
435
436
437
438
439
440
441
442
443
|
# File 'lib/tmuxinator/cli.rb', line 434
def doctor
say "Checking if tmux is installed ==> "
yes_no Tmuxinator::Doctor.installed?
say "Checking if $EDITOR is set ==> "
yes_no Tmuxinator::Doctor.editor?
say "Checking if $SHELL is set ==> "
yes_no Tmuxinator::Doctor.shell?
end
|
#implode ⇒ Object
396
397
398
399
400
401
402
403
|
# File 'lib/tmuxinator/cli.rb', line 396
def implode
if yes?("Are you sure you want to delete all tmuxinator configs?", :red)
Tmuxinator::Config.directories.each do |directory|
FileUtils.remove_dir(directory)
end
say "Deleted all tmuxinator projects."
end
end
|
#list ⇒ Object
415
416
417
418
419
420
421
422
423
|
# File 'lib/tmuxinator/cli.rb', line 415
def list
say "tmuxinator projects:"
configs = Tmuxinator::Config.configs(active: options[:active])
if options[:newline]
say configs.join("\n")
else
print_in_columns configs
end
end
|
#local ⇒ Object
324
325
326
327
328
329
330
|
# File 'lib/tmuxinator/cli.rb', line 324
def local
show_version_warning if version_warning?(
options["suppress-tmux-version-warning"]
)
render_project(create_project(attach: options[:attach]))
end
|
#new(name, session = nil) ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/tmuxinator/cli.rb', line 87
def new(name, session = nil)
if session
new_project_with_session(name, session)
else
new_project(name)
end
end
|
#start(name = nil, *args) ⇒ Object
262
263
264
265
266
267
268
269
270
271
|
# File 'lib/tmuxinator/cli.rb', line 262
def start(name = nil, *args)
params = start_params(name, *args)
show_version_warning if version_warning?(
options["suppress-tmux-version-warning"]
)
project = create_project(params)
render_project(project)
end
|
#stop(name = nil) ⇒ Object
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
# File 'lib/tmuxinator/cli.rb', line 280
def stop(name = nil)
if options["project-config"]
name = nil
end
params = {
name: name,
project_config: options["project-config"]
}
show_version_warning if version_warning?(
options["suppress-tmux-version-warning"]
)
project = create_project(params)
kill_project(project)
end
|
#stop_all ⇒ Object
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
# File 'lib/tmuxinator/cli.rb', line 304
def stop_all
configs = Tmuxinator::Config.configs(active: true)
unless options[:noconfirm]
say "Stop all active projects:\n\n", :yellow
say configs.join("\n")
say "\n"
return unless yes?("Are you sure? (n/y)")
end
Project.stop_all
end
|
#version ⇒ Object
428
429
430
|
# File 'lib/tmuxinator/cli.rb', line 428
def version
say "tmuxinator #{Tmuxinator::VERSION}"
end
|