Class: Vtk::Command

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vtk/command.rb

Overview

Command class that all command inherit from

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



13
14
15
16
# File 'lib/vtk/command.rb', line 13

def initialize
  command_name = self.class.to_s.split('::').last(2).join('_').downcase
  Vtk::Analytics.new(name: command_name).log
end

Instance Method Details

#command(**options) ⇒ Object

The external commands runner



33
34
35
36
# File 'lib/vtk/command.rb', line 33

def command(**options)
  require 'tty-command'
  TTY::Command.new(options)
end

#cursorObject

The cursor movement



43
44
45
46
# File 'lib/vtk/command.rb', line 43

def cursor
  require 'tty-cursor'
  TTY::Cursor
end

#editorObject

Open a file or text in the user’s preferred editor



53
54
55
56
# File 'lib/vtk/command.rb', line 53

def editor
  require 'tty-editor'
  TTY::Editor
end

#exec_exist?(*args) ⇒ Boolean

Check if executable exists

Returns:

  • (Boolean)

See Also:



123
124
125
126
# File 'lib/vtk/command.rb', line 123

def exec_exist?(*args)
  require 'tty-which'
  TTY::Which.exist?(*args)
end

#executeObject

Execute this command

Raises:

  • (NotImplementedError)


21
22
23
24
25
26
# File 'lib/vtk/command.rb', line 21

def execute(*)
  raise(
    NotImplementedError,
    "#{self.class}##{__method__} must be implemented"
  )
end

#generatorObject

File manipulation utility methods



63
64
65
66
# File 'lib/vtk/command.rb', line 63

def generator
  require 'tty-file'
  TTY::File
end

#pager(**options) ⇒ Object

Terminal output paging



73
74
75
76
# File 'lib/vtk/command.rb', line 73

def pager(**options)
  require 'tty-pager'
  TTY::Pager.new(options)
end

#platformObject

Terminal platform and OS properties



83
84
85
86
# File 'lib/vtk/command.rb', line 83

def platform
  require 'tty-platform'
  TTY::Platform.new
end

#prompt(**options) ⇒ Object

The interactive prompt



93
94
95
96
# File 'lib/vtk/command.rb', line 93

def prompt(**options)
  require 'tty-prompt'
  TTY::Prompt.new(options)
end

#screenObject

Get terminal screen properties



103
104
105
106
# File 'lib/vtk/command.rb', line 103

def screen
  require 'tty-screen'
  TTY::Screen
end

#which(*args) ⇒ Object

The unix which utility



113
114
115
116
# File 'lib/vtk/command.rb', line 113

def which(*args)
  require 'tty-which'
  TTY::Which.which(*args)
end