Class: Logi::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/logi/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/logi/cli.rb', line 100

def self.exit_on_failure?
  true
end

Instance Method Details

#loginObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/logi/cli.rb', line 54

def 
  api_url    = options[:api_url] || ENV["LOGI_API_URL"] || Config::DEFAULT_API_URL
  portal_url = options[:portal_url] || ENV["LOGI_PORTAL_URL"]

  if options[:code]
    Commands::DeviceLogin.perform(api_url: api_url, portal_url: portal_url)
  else
    Commands::Login.perform(
      api_url:    api_url,
      portal_url: portal_url,
      name:       options[:name],
      scopes:     options[:scope]
    )
  end
end

#logoutObject



85
86
87
88
# File 'lib/logi/cli.rb', line 85

def logout
  Config.clear
  puts "✓ Signed out (credentials deleted)"
end

#versionObject



44
45
46
# File 'lib/logi/cli.rb', line 44

def version
  puts "logi-cli #{Logi::VERSION}"
end

#welcomeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/logi/cli.rb', line 9

def welcome
  pastel = Pastel.new
  logged_in = Config.load.authenticated?

  puts pastel.bold("logi") + pastel.dim(" — Identity Provider CLI")
  puts ""

  if logged_in
    config = Config.load
    puts pastel.green("✓ Signed in") + pastel.dim("#{config.api_url}")
    puts ""
    puts pastel.bold("Common commands")
    puts "  logi apps list                                # List your OAuth apps"
    puts "  logi apps create --name \"My App\" -r URL       # Register a new app"
    puts "  logi apps verify <id> -r URL                 # Check an RP integration (env / redirect URI)"
    puts "  logi apps rotate-secret <id>                  # Rotate client_secret"
    puts "  logi whoami                                   # Show sign-in info"
    puts "  logi --help                                   # All commands"
  else
    puts pastel.yellow("You're not signed in yet.")
    puts ""
    puts pastel.bold("Get started in 3 steps:")
    puts pastel.dim("  1.") + " " + pastel.cyan("logi login") + pastel.dim("                              # Sign in via your browser")
    puts pastel.dim("  2.") + " " + pastel.cyan("logi apps create --name \"App name\" -r URL") + pastel.dim("  # Register your first app")
    puts pastel.dim("  3.") + " " + pastel.cyan("logi apps list") + pastel.dim("                          # Check your apps")
    puts ""
    puts pastel.dim("Docs: https://docs.1pass.dev")
  end
end

#whoamiObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/logi/cli.rb', line 71

def whoami
  config = Config.load
  pastel = Pastel.new
  unless config.authenticated?
    abort pastel.red("You're not signed in. Run `logi login`.")
  end

  puts "API URL: #{config.api_url}"
  puts "Source:  #{config.source}"
  puts "Name:    #{config.name || '-'}"
  puts "PAK:     #{config.api_key[0, 18]}"
end