From b98bc74f0b07c61b19610c7987d66f4711a1ccc1 Mon Sep 17 00:00:00 2001 From: Olli Vanhoja Date: Sat, 8 Oct 2016 14:07:28 +0300 Subject: [PATCH] Don't print the list if there is no entries --- bin/now-alias | 2 +- bin/now-certs | 39 +++++++++++++++++++++------------------ bin/now-domains | 2 +- bin/now-secrets | 24 +++++++++++++----------- 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/bin/now-alias b/bin/now-alias index cdd0139..d8bdef3 100755 --- a/bin/now-alias +++ b/bin/now-alias @@ -127,7 +127,7 @@ async function run (token) { const current = new Date(); 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 target = _alias.deploymentId; const _sourceUrl = urls.get(target) diff --git a/bin/now-certs b/bin/now-certs index 6fde9c7..40bc0ee 100755 --- a/bin/now-certs +++ b/bin/now-certs @@ -113,24 +113,27 @@ async function run (token) { const list = await certs.ls(); const elapsed = ms(new Date() - start); console.log(`> ${list.length} certificate${list.length > 1 ? 's' : ''} found ${chalk.gray(`[${elapsed}]`)}`); - const cur = Date.now(); - list.sort((a, b) => { - return a.cn.localeCompare(b.cn); - }); - const header = [['', 'id', 'cn', 'created', 'expiration'].map(s => chalk.dim(s))]; - const out = table(header.concat(list.map((cert) => { - const cn = chalk.bold(cert.cn); - const time = chalk.gray(ms(cur - new Date(cert.created)) + ' ago'); - const expiration = formatExpirationDate(new Date(cert.expiration)); - return [ - '', - cert.uid ? cert.uid : 'unknown', - cn, - time, - expiration - ]; - })), { align: ['l', 'r', 'l', 'l', 'l'], hsep: ' '.repeat(2), stringLength: strlen }); - if (out) console.log('\n' + out + '\n'); + + if (0 < list.length) { + const cur = Date.now(); + list.sort((a, b) => { + return a.cn.localeCompare(b.cn); + }); + const header = [['', 'id', 'cn', 'created', 'expiration'].map(s => chalk.dim(s))]; + const out = table(header.concat(list.map((cert) => { + const cn = chalk.bold(cert.cn); + const time = chalk.gray(ms(cur - new Date(cert.created)) + ' ago'); + const expiration = formatExpirationDate(new Date(cert.expiration)); + return [ + '', + cert.uid ? cert.uid : 'unknown', + cn, + time, + expiration + ]; + })), { align: ['l', 'r', 'l', 'l', 'l'], hsep: ' '.repeat(2), stringLength: strlen }); + if (out) console.log('\n' + out + '\n'); + } } else if ('create' === subcommand) { if (1 !== args.length) { error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs create `')}`); diff --git a/bin/now-domains b/bin/now-domains index 7a4b8cd..a6823fa 100755 --- a/bin/now-domains +++ b/bin/now-domains @@ -129,7 +129,7 @@ async function run (token) { domains.sort((a, b) => new Date(b.created) - new Date(a.created)); const current = new Date(); 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 url = chalk.underline(`https://${domain.name}`); const time = chalk.gray(ms(current - new Date(domain.created)) + ' ago'); diff --git a/bin/now-secrets b/bin/now-secrets index a755202..a5c7d79 100755 --- a/bin/now-secrets +++ b/bin/now-secrets @@ -112,17 +112,19 @@ async function run (token) { const list = await secrets.ls(); const elapsed = ms(new Date() - start); console.log(`> ${list.length} secret${list.length > 1 ? 's' : ''} found ${chalk.gray(`[${elapsed}]`)}`); - const cur = Date.now(); - const header = [['', 'id', 'name', 'created'].map(s => chalk.dim(s))]; - const out = table(header.concat(list.map((secret) => { - return [ - '', - secret.uid, - 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'); + if (0 < list.length) { + const cur = Date.now(); + const header = [['', 'id', 'name', 'created'].map(s => chalk.dim(s))]; + const out = table(header.concat(list.map((secret) => { + return [ + '', + secret.uid, + 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'); + } return secrets.close(); }