Class: Dri::Command

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Main configuration



21
22
23
# File 'lib/dri/command.rb', line 21

def config
  @config
end

#emojiObject (readonly)

Returns the value of attribute emoji.



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

def emoji
  @emoji
end

#profileObject (readonly)

Returns the value of attribute profile.



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

def profile
  @profile
end

#timezoneObject (readonly)

Returns the value of attribute timezone.



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

def timezone
  @timezone
end

#tokenObject (readonly)

Returns the value of attribute token.



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

def token
  @token
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#add_color(str, *color) ⇒ Object



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

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

#api_clientObject



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

def api_client
  ApiClient.new(config)
end

#command(**options) ⇒ Object

The external commands runner



92
93
94
95
# File 'lib/dri/command.rb', line 92

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

#cursorObject

The cursor movement



102
103
104
105
# File 'lib/dri/command.rb', line 102

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

#editorObject

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



112
113
114
115
# File 'lib/dri/command.rb', line 112

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

#executeObject

Execute this command

Raises:

  • (NotImplementedError)


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

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

#loggerObject



77
78
79
80
# File 'lib/dri/command.rb', line 77

def logger
  require 'tty-logger'
  TTY::Logger.new
end

#pastel(**options) ⇒ Object



16
17
18
# File 'lib/dri/command.rb', line 16

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

#prompt(**options) ⇒ Object

The interactive prompt



122
123
124
125
# File 'lib/dri/command.rb', line 122

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

#spinnerObject



82
83
84
85
# File 'lib/dri/command.rb', line 82

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

#verify_config_existsObject



56
57
58
59
60
61
# File 'lib/dri/command.rb', line 56

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