Skip to content

Commit

Permalink
feat: pretty print the cli if it is outputing to a tty
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Jan 17, 2020
1 parent 025abed commit d406059
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/cog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@cogeotiff/source-url": "^0.8.0",
"@mapbox/tile-cover": "^3.0.2",
"p-limit": "^2.2.1",
"pretty-json-log": "^0.2.2",
"proj4": "^2.6.0"
},
"devDependencies": {
Expand Down
15 changes: 12 additions & 3 deletions packages/cog/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env node
import 'source-map-support/register';
import { CommandLineParser } from '@microsoft/ts-command-line';
import { LogConfig } from '@basemaps/shared';
import { CommandLineParser } from '@microsoft/ts-command-line';
import { PrettyTransform } from 'pretty-json-log';
import 'source-map-support/register';
import { ActionCogCreate } from './actions/action.cog';
import { ActionCogJobCreate } from './actions/action.job';

Expand All @@ -28,6 +29,12 @@ export class CogifyCommandLine extends CommandLineParser {

protected onExecute(): Promise<void> {
const logger = LogConfig.get();

// If the console is a tty pretty print the output
if (process.stdout.isTTY) {
LogConfig.setOutputStream(PrettyTransform.stream());
}

if (this.verbose.value) {
logger.level = 'info';
} else if (this.extraVerbose.value) {
Expand All @@ -43,4 +50,6 @@ export class CogifyCommandLine extends CommandLineParser {
}
}

new CogifyCommandLine().execute();
new CogifyCommandLine()
.executeWithoutErrorHandling()
.catch(err => LogConfig.get().fatal({ err }, 'Failed to run command'));
45 changes: 44 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,14 @@ ansi-styles@^4.0.0:
"@types/color-name" "^1.1.1"
color-convert "^2.0.1"

ansi-styles@^4.1.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.1.tgz#90ae75c424d008d2624c5bf29ead3177ebfcf359"
integrity sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==
dependencies:
"@types/color-name" "^1.1.1"
color-convert "^2.0.1"

any-promise@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"
Expand Down Expand Up @@ -2901,6 +2909,14 @@ chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.1, chalk@^2.4.
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chalk@3:
version "3.0.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4"
integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chardet@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
Expand Down Expand Up @@ -4853,6 +4869,11 @@ has-flag@^3.0.0:
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=

has-flag@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==

has-symbols@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.1.tgz#9f5214758a44196c406d9bd76cebf81ec2dd31e8"
Expand Down Expand Up @@ -7576,6 +7597,14 @@ pretty-format@^24.9.0:
ansi-styles "^3.2.0"
react-is "^16.8.4"

pretty-json-log@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/pretty-json-log/-/pretty-json-log-0.2.2.tgz#4182a5cef7627f1271db76d34c07bfeb2bb4bf19"
integrity sha512-KR5b47i2o7NxBIpVlXt8R2whMx8Ta4QoU5Q2FEr4WcmsrtpBz+O9nSrrEddYgdeHeBJOmPckQsynWQWS/CSNsg==
dependencies:
chalk "3"
split2 "^3.1.1"

process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
Expand Down Expand Up @@ -7931,7 +7960,7 @@ readable-stream@1.1.x:
isarray "0.0.1"
string_decoder "~0.10.x"

"readable-stream@2 || 3", readable-stream@^3.0.1, readable-stream@^3.0.2, readable-stream@^3.1.1, readable-stream@^3.4.0:
"readable-stream@2 || 3", readable-stream@^3.0.0, readable-stream@^3.0.1, readable-stream@^3.0.2, readable-stream@^3.1.1, readable-stream@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.4.0.tgz#a51c26754658e0a3c21dbf59163bd45ba6f447fc"
integrity sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==
Expand Down Expand Up @@ -8616,6 +8645,13 @@ split2@^2.0.0:
dependencies:
through2 "^2.0.2"

split2@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/split2/-/split2-3.1.1.tgz#c51f18f3e06a8c4469aaab487687d8d956160bb6"
integrity sha512-emNzr1s7ruq4N+1993yht631/JH+jaj0NYBosuKmLcq+JkGQ9MmTw1RB1fGaTCzUuseRIClrlSLHRNYGwWQ58Q==
dependencies:
readable-stream "^3.0.0"

split@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/split/-/split-1.0.1.tgz#605bd9be303aa59fb35f9229fbea0ddec9ea07d9"
Expand Down Expand Up @@ -8873,6 +8909,13 @@ supports-color@^5.3.0:
dependencies:
has-flag "^3.0.0"

supports-color@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.1.0.tgz#68e32591df73e25ad1c4b49108a2ec507962bfd1"
integrity sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==
dependencies:
has-flag "^4.0.0"

symbol-tree@^3.2.2:
version "3.2.4"
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
Expand Down

0 comments on commit d406059

Please sign in to comment.