Class: Terminalwire::Client::Exec

Inherits:
Object
  • Object
show all
Defined in:
lib/terminalwire/client/exec.rb

Overview

Called by the ‘terminalwire-exec` shebang in scripts. This makes it easy for people to create their own scripts that use Terminalwire that look like this:

“‘sh #!/usr/bin/env terminalwire-exec url: “terminalwire.com/terminal” “`

These files are saved, then ‘chmod + x` is run on them and they become executable.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, arguments:) ⇒ Exec

Returns a new instance of Exec.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/terminalwire/client/exec.rb', line 18

def initialize(path:, arguments:)
  @arguments = arguments
  @path = Pathname.new(path)
  @configuration = YAML.safe_load_file(@path)
  @url = URI(@configuration.fetch("url"))
rescue Errno::ENOENT => e
  raise Terminalwire::Error, "File not found: #{@path}"
rescue URI::InvalidURIError => e
  raise Terminalwire::Error, "Invalid URI: #{@url}"
rescue KeyError => e
  raise Terminalwire::Error, "Missing key in configuration: #{e}"
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



16
17
18
# File 'lib/terminalwire/client/exec.rb', line 16

def arguments
  @arguments
end

#configurationObject (readonly)

Returns the value of attribute configuration.



16
17
18
# File 'lib/terminalwire/client/exec.rb', line 16

def configuration
  @configuration
end

#pathObject (readonly)

Returns the value of attribute path.



16
17
18
# File 'lib/terminalwire/client/exec.rb', line 16

def path
  @path
end

#urlObject (readonly)

Returns the value of attribute url.



16
17
18
# File 'lib/terminalwire/client/exec.rb', line 16

def url
  @url
end

Class Method Details

.startObject



35
36
37
38
39
40
41
42
# File 'lib/terminalwire/client/exec.rb', line 35

def self.start
  case ARGV
  in path, *arguments
    new(path:, arguments:).start
  end
rescue NoMatchingPatternError => e
  raise Terminalwire::Error, "Launched with incorrect arguments: #{ARGV}"
end

Instance Method Details

#startObject



31
32
33
# File 'lib/terminalwire/client/exec.rb', line 31

def start
  Terminalwire::Client.websocket(url:, arguments:)
end