Class: OAuth::TTY::Command

Inherits:
Object
  • Object
show all
Includes:
AUTH_SANITIZER::FilteredAttributes
Defined in:
lib/oauth/tty/command.rb,
sig/oauth/tty/command.rbs

Overview

Base class for oauth-tty commands.

Includes OAuth::TTY::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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Command.

Parameters:

  • stdout (Object)
  • stdin (Object)
  • stderr (Object)
  • arguments (Object)


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 Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.

Returns:

  • (Object)


53
54
55
# File 'lib/oauth/tty/command.rb', line 53

def options
  @options
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_optionsArray[untyped]

Returns:

  • (Array[untyped])


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

def required_options
  []
end

#runObject

Returns:

  • (Object)


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