Class: Ace::Tmux::CLI::Commands::Start

Inherits:
Support::Cli::Command
  • Object
show all
Includes:
Support::Cli::Base
Defined in:
lib/ace/tmux/cli/commands/start.rb

Overview

Start a tmux session from a preset

Instance Method Summary collapse

Instance Method Details

#call(preset: nil, **options) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ace/tmux/cli/commands/start.rb', line 49

def call(preset: nil, **options)
  config = Tmux.config
  tmux_bin = config.dig("tmux_binary") || "tmux"

  preset ||= config.dig("defaults", "session")
  raise Ace::Support::Cli::Error.new("No preset specified and no default session configured") unless preset

  preset_loader = Molecules::PresetLoader.new(
    gem_root: Tmux.gem_root
  )
  session_builder = Molecules::SessionBuilder.new(
    preset_loader: preset_loader
  )
  executor = Molecules::TmuxExecutor.new
  manager = Organisms::SessionManager.new(
    executor: executor,
    session_builder: session_builder,
    tmux: tmux_bin
  )

  session_name = options[:name] || preset
  puts "Starting session '#{session_name}'..." unless options[:quiet]
  manager.start(
    preset,
    detach: options[:detach] || false,
    force: options[:force] || false,
    name: options[:name],
    root: options[:root]
  )
  puts "Session '#{session_name}' created." if options[:detach] && !options[:quiet]
rescue Ace::Tmux::PresetNotFoundError => e
  raise Ace::Support::Cli::Error.new(e.message)
end