UNPKG

@adinsure-ops/ops-cli

Version:

Operations CLI for working with AdInsure

43 lines (42 loc) 1.69 kB
import { __awaiter } from "tslib"; import { Flags } from '@oclif/core'; import chalk from 'chalk'; import fs from 'fs'; import CommandBase from '../command.base.js'; class LoginRu extends CommandBase { run() { const _super = Object.create(null, { run: { get: () => super.run } }); return __awaiter(this, void 0, void 0, function* () { _super.run.call(this); const { flags } = yield this.parse(LoginRu); // const configDir = this.config.configDir; // should work? // Instantiate SecurityContext with a custom token file name // const security = new SecurityContext(configDir, 'accessTokenRu.json'); const tokenFile = this.security.getTokenRuPath(); if (flags.force && fs.existsSync(tokenFile)) { fs.unlinkSync(tokenFile); this.log(chalk.yellow('Existing GitLabRu token removed due to force flag.')); } // Here we simply store the token in the same JSON format fs.writeFileSync(tokenFile, JSON.stringify({ accessTokenRu: flags.token }), 'utf8'); this.log(chalk.green('GitLabRu token stored successfully!')); }); } } LoginRu.aliases = ['login:ru']; LoginRu.description = 'Log in to use ops services with GitLabRu token'; LoginRu.usage = 'login:ru --token <token>'; LoginRu.examples = [`$ ops login:ru --token abc123`]; LoginRu.flags = { token: Flags.string({ description: 'The GitLabRu token to store', required: true, }), force: Flags.boolean({ description: 'Force update of token', default: false, }), }; export default LoginRu;