@zendesk/zcli
Version:
Zendesk CLI is a single command line tool for all your zendesk needs
46 lines (45 loc) • 1.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const chalk = require("chalk");
const zcli_core_1 = require("@zendesk/zcli-core");
const helpMessage_1 = require("../utils/helpMessage");
class Login extends core_1.Command {
async run() {
const secureStore = new zcli_core_1.SecureStore();
const keytar = await secureStore.loadKeytar();
if (!keytar) {
console.log(chalk.yellow('Failed to load secure credentials store: use environment variables to log in.'), helpMessage_1.HELP_ENV_VARS);
return;
}
const { flags } = await this.parse(Login);
const { interactive, subdomain, domain } = flags;
if (interactive) {
const auth = new zcli_core_1.Auth({ secureStore });
const success = await auth.loginInteractively({ subdomain, domain });
if (success) {
console.log(chalk.green('Successfully logged in.'));
}
else {
const account = (0, zcli_core_1.getAccount)(subdomain, domain);
console.log(chalk.red(`Failed to log in to your account: ${account}.`));
}
}
else {
console.log('Browser login coming soon, use `zcli login -i` for interactive logins.');
}
}
}
exports.default = Login;
Login.description = 'creates and/or saves an authentication token for the specified subdomain';
Login.flags = {
help: core_1.Flags.help({ char: 'h' }),
subdomain: core_1.Flags.string({ char: 's', default: '', description: 'Zendesk Subdomain' }),
domain: core_1.Flags.string({ char: 'd', description: 'Zendesk domain' }),
interactive: core_1.Flags.boolean({ char: 'i', default: false, description: 'Use Terminal based login' })
};
Login.examples = [
'$ zcli login -i',
'$ zcli login -s zendesk-subdomain -i',
'$ zcli login -s zendesk-subdomain -d example.com -i'
];