Class: OAuth::TTY::Command

Inherits:
Object
  • Object
show all
Includes:
Auth::Sanitizer::FilteredAttributes
Defined in:
lib/oauth/tty/command.rb

Overview

Base class for oauth-tty commands.

Includes Auth::Sanitizer::FilteredAttributes so inspect output redacts the accumulated command options hash, which may contain consumer or token secrets read from CLI flags or option files.

Instance Method Summary collapse

Constructor Details

#initialize(stdout, stdin, stderr, arguments) ⇒ Command

Returns a new instance of Command.



17
18
19
20
21
22
23
24
# File 'lib/oauth/tty/command.rb', line 17

def initialize(stdout, stdin, stderr, arguments)
  @stdout = stdout
  @stdin = stdin
  @stderr = stderr

  @options = {}
  option_parser.parse!(arguments)
end

Instance Method Details

#inspectObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/oauth/tty/command.rb', line 26

def inspect
  format(
    "#<%<klass>s:0x%<object_id>x @stdout=%<stdout>s, @stdin=%<stdin>s, @stderr=%<stderr>s, @options=[FILTERED], @option_parser=[FILTERED]>",
    klass: self.class,
    object_id: object_id,
    stdout: @stdout.inspect,
    stdin: @stdin.inspect,
    stderr: @stderr.inspect,
  )
end

#required_optionsObject



47
48
49
# File 'lib/oauth/tty/command.rb', line 47

def required_options
  []
end

#runObject



37
38
39
40
41
42
43
44
45
# File 'lib/oauth/tty/command.rb', line 37

def run
  missing = required_options - options.keys
  if missing.empty?
    _run
  else
    show_missing(missing)
    puts option_parser.help
  end
end