Method: BooticCli::CLI#setup

Defined in:
lib/bootic_cli/cli.rb

#setupObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bootic_cli/cli.rb', line 28

def setup
  apps_host   = "auth.bootic.net"
  dev_app_url = "#{apps_host}/dev/cli"

  if session.setup?
    input = ask "Looks like you're already set up. Do you want to re-enter your app's credentials? [n]", :magenta
    if input != 'y'
      say 'Thought so. You can run `bootic help` for a list of supported commands.'
      exit(1)
    end
  else
    say "This CLI uses the #{bold('Bootic API')} in order to interact with your shop's data."
    say "This means you need to create a Bootic app at #{bold(dev_app_url)} to access the API and use the CLI.\n"
  end

  input = ask "Have you created a Bootic app yet? [n]"
  if input == 'y'
    say "Great. Remember you can get your app's credentials at #{bold(dev_app_url)}."
  else
    say "Please visit https://#{bold(dev_app_url)} and hit the 'Create' button."
    sleep 2
    # Launchy.open(apps_url)
    say ""
  end

  if current_env != DEFAULT_ENV
    auth_host = ask("Enter auth endpoint host (#{BooticClient.configuration.auth_host}):", :bold).chomp
    api_root  = ask("Enter API root (#{BooticClient.configuration.api_root}):", :bold).chomp
    auth_host = nil if auth_host == ""
    api_root  = nil if api_root == ""
  end

  client_id     = ask("Enter your application's client_id:", :bold)
  client_secret = ask("Enter your application's client_secret:", :bold)

  session.setup(client_id, client_secret, auth_host: auth_host, api_root: api_root)

  if current_env == DEFAULT_ENV
    say "Credentials stored!", :magenta
  else
    say "Credentials stored for #{current_env} env.", :magenta
  end

  return if ENV['nologin']

  say ""
  sleep 3
  
end