steadybit
Version:
Command-line interface to interact with the Steadybit API
90 lines (88 loc) • 3.66 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.add = add;
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2022 Steadybit GmbH
const safe_1 = __importDefault(require("colors/safe"));
const inquirer_1 = __importDefault(require("inquirer"));
const validation_1 = require("../../prompt/validation");
const service_1 = require("./service");
const __1 = require("..");
const startHelp = `
Configuration profiles enable you to use the CLI without repeatedly providing
passwords or having to remember environment variables. Configuration profiles
are stored in ~/.steadybit
`.trim();
const finishHelp = `
${safe_1.default.green('Done!')} You can now start using the CLI. For example, you could start
to run your first experiment via:
${safe_1.default.bold('steadybit experiment run -k <your-key>')}
`.trim();
function add(options) {
return __awaiter(this, void 0, void 0, function* () {
let profile;
console.log(options);
if ((options === null || options === void 0 ? void 0 : options.name) && (options === null || options === void 0 ? void 0 : options.token)) {
profile = {
name: options.name,
baseUrl: options.baseUrl,
apiAccessToken: options.token,
};
}
else {
console.clear();
console.log(startHelp);
console.log();
profile = yield ask();
}
yield (0, service_1.addProfile)(profile);
console.log();
console.log(finishHelp);
});
}
function ask() {
return __awaiter(this, void 0, void 0, function* () {
const answers1 = yield inquirer_1.default.prompt([
{
type: 'input',
name: 'name',
message: 'Profile name:',
validate: validation_1.validateNotBlank,
},
{
type: 'input',
name: 'baseUrl',
message: 'Base URL of the Steadybit server:',
default: __1.defaultBaseUrl,
validate: validation_1.validateHttpUrl,
},
]);
console.log(`
The CLI will need an API access token of ${safe_1.default.bold('type team')} to communicate with
the Steadybit servers. You can generate one through the following URL:
${answers1.baseUrl.replace(/\/$/, '')}/settings/api-tokens
`);
const answers2 = yield inquirer_1.default.prompt([
{
type: 'password',
name: 'apiAccessToken',
message: 'API access token:',
validate: validation_1.validateNotBlank,
},
]);
return Object.assign(Object.assign({}, answers1), answers2);
});
}
//# sourceMappingURL=add.js.map