@liara/cli
Version:
The command line interface for Liara
64 lines (63 loc) • 2.26 kB
JavaScript
import inquirer from 'inquirer';
import Command from '../../base.js';
import { Flags } from '@oclif/core';
import { createDebugLogger } from '../../utils/output.js';
import { ux } from '@oclif/core';
class Check extends Command {
async run() {
const { flags } = await this.parse(Check);
await this.setGotConfig(flags);
const debug = createDebugLogger(flags.debug);
await this.setGotConfig(flags);
const zone = flags.zone || (await this.promptZone());
try {
const { data } = await this.got
.put(Check.PATH.replace('{zone}', zone))
.json();
this.log(data);
}
catch (error) {
debug(error.message);
if (error.response && error.response.body) {
debug(JSON.stringify(error.response.body));
}
if (error.response && error.response.statusCode === 400) {
this.error(`Enter correct domain name.`);
}
if (error.response && error.response.statusCode === 404) {
this.error(`Zone does not exists or its status is not pending.`);
}
if (error.response && error.response.statusCode === 406) {
this.error(`System is checking your domain... Please try again later.`);
}
this.error(`Could not check the zone. Please try again.`);
}
}
async setGotConfig(config) {
await super.setGotConfig(config);
const new_got = this.got.extend({ prefixUrl: Check.baseURL });
this.got = new_got; // baseURL is different for zone api
}
async promptZone() {
const { zone } = (await inquirer.prompt({
name: 'zone',
type: 'input',
message: 'Enter domain:',
validate: (input) => input.length > 2,
}));
return zone;
}
}
Check.description = 'check zone status';
Check.baseURL = 'https://dns-service.iran.liara.ir';
Check.PATH = 'api/v1/zones/{zone}/check';
Check.aliases = ['zone:ch'];
Check.flags = {
...Command.flags,
zone: Flags.string({
char: 'z',
description: 'name of the zone (domain)',
}),
...ux.table.flags(),
};
export default Check;