"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = retrieveUdacityAuthToken;

var _ = require(".");

var _config = require("../../config");

var _utils = require("../utils");

/**
 * Try to retrieve Udacity authentication token from local settings.
 * If it hasn't been provided, prompt for one
 */
async function retrieveUdacityAuthToken() {
  try {
    const savedToken = _utils.config.get(_config.CLI_CONFIG_UDACITY_AUTH_TOKEN);

    if (savedToken) {
      return savedToken;
    }

    _utils.logger.warn('Udacity authentication token hasn\'t been set.');

    const token = await (0, _.promptInputUdacityAuthToken)();
    const tokenValidated = await (0, _.validateSaveUdacityAuthToken)(token);
    return tokenValidated;
  } catch (error) {
    throw error;
  }
}