Class: Dri::Command

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Utils::Helpers
Defined in:
lib/dri/command.rb

Instance Method Summary collapse

Methods included from Utils::Helpers

logger

Constructor Details

#initialize(*options) ⇒ Command

Returns a new instance of Command.



23
24
25
# File 'lib/dri/command.rb', line 23

def initialize(*options)
  @options = options
end

Instance Method Details

#add_color(str, *color) ⇒ Object



42
43
44
# File 'lib/dri/command.rb', line 42

def add_color(str, *color)
  @options[:no_color] ? str : pastel.decorate(str, *color)
end

#api_client(ops: false) ⇒ Object



31
32
33
# File 'lib/dri/command.rb', line 31

def api_client(ops: false)
  ApiClient.new(config, ops)
end

#bold(str) ⇒ Object



46
47
48
# File 'lib/dri/command.rb', line 46

def bold(str)
  pastel.bold(str)
end

#command(**options) ⇒ Object

The external commands runner



70
71
72
73
# File 'lib/dri/command.rb', line 70

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

#cursorObject

The cursor movement



80
81
82
83
# File 'lib/dri/command.rb', line 80

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

#editorObject

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



90
91
92
93
# File 'lib/dri/command.rb', line 90

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

#executeObject

Execute this command

Raises:

  • (NotImplementedError)


53
54
55
56
57
58
# File 'lib/dri/command.rb', line 53

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

#pastel(**options) ⇒ Object



27
28
29
# File 'lib/dri/command.rb', line 27

def pastel(**options)
  Pastel.new(**options)
end

#prompt(**options) ⇒ Object

The interactive prompt



100
101
102
103
# File 'lib/dri/command.rb', line 100

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

#spinnerObject



60
61
62
63
# File 'lib/dri/command.rb', line 60

def spinner
  require 'tty-spinner'
  TTY::Spinner.new("[:spinner] ⏳", format: :classic)
end

#verify_config_existsObject



35
36
37
38
39
40
# File 'lib/dri/command.rb', line 35

def verify_config_exists
  return if config.exist?

  logger.error "Oops, could not find a configuration. Try using #{add_color('dri init', :yellow)} first."
  exit 1
end