Class: GemContribute::CLI::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_contribute/cli/auth.rb

Overview

‘gem-contribute auth <subcommand>` — Stage 2 entry point for OAuth.

Subcommands:

login   — start device flow, poll for completion, persist the token
status  — show whether a token is cached for github.com (and try to
          validate it by hitting /user)
logout  — drop the cached token for github.com

Constant Summary collapse

USAGE =
<<~USAGE
  Usage: gem-contribute auth <subcommand>

  Subcommands:
    login    Authenticate with GitHub via OAuth device flow.
    status   Show whether you're authenticated.
    logout   Remove the cached token for github.com.
USAGE
DEFAULT_HOST =
"github.com"

Instance Method Summary collapse

Constructor Details

#initialize(stdout: $stdout, stderr: $stderr, store: TokenStore.new, sleeper: ->(s) { Kernel.sleep(s) }, browser_opener: nil, clipper: nil) ⇒ Auth

Returns a new instance of Auth.



24
25
26
27
28
29
30
31
32
33
# File 'lib/gem_contribute/cli/auth.rb', line 24

def initialize(stdout: $stdout, stderr: $stderr, store: TokenStore.new,
               sleeper: ->(s) { Kernel.sleep(s) },
               browser_opener: nil, clipper: nil)
  @stdout = stdout
  @stderr = stderr
  @store = store
  @sleeper = sleeper
  @browser_opener = browser_opener || method(:default_browser_opener)
  @clipper = clipper || method(:default_clipper)
end

Instance Method Details

#run(argv) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gem_contribute/cli/auth.rb', line 35

def run(argv)
  case argv.shift
  when "login"  then 
  when "status" then status
  when "logout" then logout
  when nil, "help", "-h", "--help"
    @stdout.puts USAGE
    0
  else
    @stderr.puts "gem-contribute: unknown auth subcommand"
    @stderr.puts USAGE
    2
  end
end