Browse Source

Don't print the list if there is no entries

master
Olli Vanhoja 8 years ago
parent
commit
b98bc74f0b
  1. 2
      bin/now-alias
  2. 39
      bin/now-certs
  3. 2
      bin/now-domains
  4. 24
      bin/now-secrets

2
bin/now-alias

@ -127,7 +127,7 @@ async function run (token) {
const current = new Date(); const current = new Date();
const header = [['', 'id', 'source', 'url', 'created'].map(s => chalk.dim(s))]; const header = [['', 'id', 'source', 'url', 'created'].map(s => chalk.dim(s))];
const text = table(header.concat(aliases.map((_alias) => { const text = 0 === list.length ? null : table(header.concat(aliases.map((_alias) => {
const _url = chalk.underline(`https://${_alias.alias}`); const _url = chalk.underline(`https://${_alias.alias}`);
const target = _alias.deploymentId; const target = _alias.deploymentId;
const _sourceUrl = urls.get(target) const _sourceUrl = urls.get(target)

39
bin/now-certs

@ -113,24 +113,27 @@ async function run (token) {
const list = await certs.ls(); const list = await certs.ls();
const elapsed = ms(new Date() - start); const elapsed = ms(new Date() - start);
console.log(`> ${list.length} certificate${list.length > 1 ? 's' : ''} found ${chalk.gray(`[${elapsed}]`)}`); console.log(`> ${list.length} certificate${list.length > 1 ? 's' : ''} found ${chalk.gray(`[${elapsed}]`)}`);
const cur = Date.now();
list.sort((a, b) => { if (0 < list.length) {
return a.cn.localeCompare(b.cn); const cur = Date.now();
}); list.sort((a, b) => {
const header = [['', 'id', 'cn', 'created', 'expiration'].map(s => chalk.dim(s))]; return a.cn.localeCompare(b.cn);
const out = table(header.concat(list.map((cert) => { });
const cn = chalk.bold(cert.cn); const header = [['', 'id', 'cn', 'created', 'expiration'].map(s => chalk.dim(s))];
const time = chalk.gray(ms(cur - new Date(cert.created)) + ' ago'); const out = table(header.concat(list.map((cert) => {
const expiration = formatExpirationDate(new Date(cert.expiration)); const cn = chalk.bold(cert.cn);
return [ const time = chalk.gray(ms(cur - new Date(cert.created)) + ' ago');
'', const expiration = formatExpirationDate(new Date(cert.expiration));
cert.uid ? cert.uid : 'unknown', return [
cn, '',
time, cert.uid ? cert.uid : 'unknown',
expiration cn,
]; time,
})), { align: ['l', 'r', 'l', 'l', 'l'], hsep: ' '.repeat(2), stringLength: strlen }); expiration
if (out) console.log('\n' + out + '\n'); ];
})), { align: ['l', 'r', 'l', 'l', 'l'], hsep: ' '.repeat(2), stringLength: strlen });
if (out) console.log('\n' + out + '\n');
}
} else if ('create' === subcommand) { } else if ('create' === subcommand) {
if (1 !== args.length) { if (1 !== args.length) {
error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs create <cn>`')}`); error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs create <cn>`')}`);

2
bin/now-domains

@ -129,7 +129,7 @@ async function run (token) {
domains.sort((a, b) => new Date(b.created) - new Date(a.created)); domains.sort((a, b) => new Date(b.created) - new Date(a.created));
const current = new Date(); const current = new Date();
const header = [['', 'id', 'dns', 'url', 'created'].map(s => chalk.dim(s))]; const header = [['', 'id', 'dns', 'url', 'created'].map(s => chalk.dim(s))];
const out = table(header.concat(domains.map((domain) => { const out = domains.length === 0 ? null : table(header.concat(domains.map((domain) => {
const ns = domain.isExternal ? 'external' : 'zeit.world'; const ns = domain.isExternal ? 'external' : 'zeit.world';
const url = chalk.underline(`https://${domain.name}`); const url = chalk.underline(`https://${domain.name}`);
const time = chalk.gray(ms(current - new Date(domain.created)) + ' ago'); const time = chalk.gray(ms(current - new Date(domain.created)) + ' ago');

24
bin/now-secrets

@ -112,17 +112,19 @@ async function run (token) {
const list = await secrets.ls(); const list = await secrets.ls();
const elapsed = ms(new Date() - start); const elapsed = ms(new Date() - start);
console.log(`> ${list.length} secret${list.length > 1 ? 's' : ''} found ${chalk.gray(`[${elapsed}]`)}`); console.log(`> ${list.length} secret${list.length > 1 ? 's' : ''} found ${chalk.gray(`[${elapsed}]`)}`);
const cur = Date.now(); if (0 < list.length) {
const header = [['', 'id', 'name', 'created'].map(s => chalk.dim(s))]; const cur = Date.now();
const out = table(header.concat(list.map((secret) => { const header = [['', 'id', 'name', 'created'].map(s => chalk.dim(s))];
return [ const out = table(header.concat(list.map((secret) => {
'', return [
secret.uid, '',
chalk.bold(secret.name), secret.uid,
chalk.gray(ms(cur - new Date(secret.created)) + ' ago') chalk.bold(secret.name),
]; chalk.gray(ms(cur - new Date(secret.created)) + ' ago')
})), { align: ['l', 'r', 'l', 'l'], hsep: ' '.repeat(2), stringLength: strlen }); ];
if (out) console.log('\n' + out + '\n'); })), { align: ['l', 'r', 'l', 'l'], hsep: ' '.repeat(2), stringLength: strlen });
if (out) console.log('\n' + out + '\n');
}
return secrets.close(); return secrets.close();
} }

Loading…
Cancel
Save