Class: Teamocil::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/teamocil/cli.rb

Overview

This class handles interaction with the tmux utility.

Instance Method Summary (collapse)

Constructor Details

- (CLI) initialize(argv, env)

Initialize a new run of tmux

Parameters:

  • argv (Hash)

    the command line parameters hash (usually ARGV).

  • env (Hash)

    the environment variables hash (usually ENV).



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/teamocil/cli.rb', line 12

def initialize(argv, env) # {{{
  bail "You must be in a tmux session to use teamocil" unless env["TMUX"]

  parse_options!
  if @options.include?(:layout)
    file = options[:layout]
  else
    file = ::File.join("#{env["HOME"]}/.teamocil", "#{argv[0]}.yml")
  end

  if @options[:edit]
    ::FileUtils.touch file unless File.exists?(file)
    system("$EDITOR \"#{file}\"")
  else
    bail "There is no file \"#{file}\"" unless File.exists?(file)
    layout = Teamocil::Layout.new(file, @options)
    layout.to_tmux
  end
end

Instance Method Details

- (Object) bail(msg)

Print an error message and exit the utility

Parameters:

  • msg (Mixed)

    something to print before exiting.



59
60
61
62
# File 'lib/teamocil/cli.rb', line 59

def bail(msg) # {{{
  puts "[teamocil] #{msg}"
  exit 1
end

- (Object) parse_options!

Parse the command line options



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/teamocil/cli.rb', line 33

def parse_options! 
  @options = {}
  opts = ::OptionParser.new do |opts|
    opts. = "Usage: teamocil [options] <layout>

  Options:
    "
    opts.on("--here", "Set up the first window in the current window") do
      @options[:here] = true
    end

    opts.on("--edit", "Edit the YAML layout file instead of using it") do
      @options[:edit] = true
    end

    opts.on("--layout [LAYOUT]", "Use a specific layout file, instead of ~/.teamocil/<layout>.yml") do |layout|
      @options[:layout] = layout
    end

  end
  opts.parse!
end