From 4da0b369b79a2f50909bca732211c147f6bab26b Mon Sep 17 00:00:00 2001 From: Max Schmeling Date: Mon, 22 Apr 2024 15:10:40 -0500 Subject: [PATCH] Fix duplicate format option on slowlogs command (#1785) --- __tests__/bin/vip-logs.js | 10 +++++----- __tests__/bin/vip-slowlogs.js | 10 +++++----- src/bin/vip-logs.js | 6 +++--- src/bin/vip-slowlogs.ts | 8 ++++---- src/lib/app-slowlogs/types.ts | 10 +++------- src/lib/cli/format.ts | 12 +++++------- 6 files changed, 25 insertions(+), 31 deletions(-) diff --git a/__tests__/bin/vip-logs.js b/__tests__/bin/vip-logs.js index 5c74a573e..7a66d8a73 100644 --- a/__tests__/bin/vip-logs.js +++ b/__tests__/bin/vip-logs.js @@ -48,7 +48,7 @@ describe( 'getLogs', () => { }, type: 'app', limit: 500, - format: 'text', + format: 'table', }; } ); @@ -81,7 +81,7 @@ describe( 'getLogs', () => { type: 'app', limit: 500, follow: false, - format: 'text', + format: 'table', }; expect( tracker.trackEvent ).toHaveBeenCalledTimes( 2 ); @@ -213,7 +213,7 @@ describe( 'getLogs', () => { type: 'app', limit: 500, follow: false, - format: 'text', + format: 'table', }; expect( tracker.trackEvent ).toHaveBeenNthCalledWith( @@ -253,7 +253,7 @@ describe( 'getLogs', () => { type: 'app', limit: 500, follow: false, - format: 'text', + format: 'table', }; expect( tracker.trackEvent ).toHaveBeenCalledTimes( 2 ); @@ -296,7 +296,7 @@ describe( 'getLogs', () => { expect( exit.withError ).toHaveBeenCalledTimes( 1 ); expect( exit.withError ).toHaveBeenCalledWith( - 'Invalid format: jso. The supported formats are: csv, json, text.' + 'Invalid format: jso. The supported formats are: csv, json, table.' ); expect( logsLib.getRecentLogs ).not.toHaveBeenCalled(); diff --git a/__tests__/bin/vip-slowlogs.js b/__tests__/bin/vip-slowlogs.js index e253c7a51..228db5c43 100644 --- a/__tests__/bin/vip-slowlogs.js +++ b/__tests__/bin/vip-slowlogs.js @@ -45,7 +45,7 @@ describe( 'getSlowlogs', () => { isK8sResident: true, }, limit: 500, - format: 'text', + format: 'table', }; } ); @@ -105,7 +105,7 @@ describe( 'getSlowlogs', () => { env_id: 3, limit: 500, follow: false, - format: 'text', + format: 'table', }; expect( tracker.trackEvent ).toHaveBeenCalledTimes( 2 ); @@ -270,7 +270,7 @@ describe( 'getSlowlogs', () => { env_id: 3, limit: 500, follow: false, - format: 'text', + format: 'table', }; expect( tracker.trackEvent ).toHaveBeenNthCalledWith( @@ -309,7 +309,7 @@ describe( 'getSlowlogs', () => { env_id: 3, limit: 500, follow: false, - format: 'text', + format: 'table', }; expect( tracker.trackEvent ).toHaveBeenCalledTimes( 2 ); @@ -333,7 +333,7 @@ describe( 'getSlowlogs', () => { expect( exit.withError ).toHaveBeenCalledTimes( 1 ); expect( exit.withError ).toHaveBeenCalledWith( - 'Invalid format: jso. The supported formats are: csv, json, text.' + 'Invalid format: jso. The supported formats are: csv, json, table.' ); expect( slowlogsLib.getRecentSlowlogs ).not.toHaveBeenCalled(); diff --git a/src/bin/vip-logs.js b/src/bin/vip-logs.js index d50dba14c..78c6cfde9 100755 --- a/src/bin/vip-logs.js +++ b/src/bin/vip-logs.js @@ -12,7 +12,7 @@ import { trackEvent } from '../lib/tracker'; const LIMIT_MIN = 1; const LIMIT_MAX = 5000; const ALLOWED_TYPES = [ 'app', 'batch' ]; -const ALLOWED_FORMATS = [ 'csv', 'json', 'text' ]; +const ALLOWED_FORMATS = [ 'csv', 'json', 'table' ]; const DEFAULT_POLLING_DELAY_IN_SECONDS = 30; const MIN_POLLING_DELAY_IN_SECONDS = 5; const MAX_POLLING_DELAY_IN_SECONDS = 300; @@ -142,7 +142,7 @@ function printLogs( logs, format ) { } ); let output = ''; - if ( format && 'text' === format ) { + if ( format && 'table' === format ) { const rows = []; for ( const { timestamp, message } of logs ) { rows.push( `${ timestamp } ${ message }` ); @@ -204,7 +204,7 @@ command( { .option( 'type', 'The type of logs to be returned: "app" or "batch"', 'app' ) .option( 'limit', 'The maximum number of log lines', 500 ) .option( 'follow', 'Keep fetching new logs as they are generated' ) - .option( 'format', 'Output the log lines in CSV or JSON format', 'text' ) + .option( 'format', 'Output the log lines in CSV or JSON format', 'table' ) .examples( [ { usage: 'vip @mysite.production logs', diff --git a/src/bin/vip-slowlogs.ts b/src/bin/vip-slowlogs.ts index ebf2ca2f0..2bc399eb5 100755 --- a/src/bin/vip-slowlogs.ts +++ b/src/bin/vip-slowlogs.ts @@ -14,12 +14,12 @@ import { } from '../lib/app-slowlogs/types'; import command from '../lib/cli/command'; import * as exit from '../lib/cli/exit'; -import { formatData } from '../lib/cli/format'; +import { OutputFormat, formatData } from '../lib/cli/format'; import { trackEvent } from '../lib/tracker'; const LIMIT_MIN = 1; const LIMIT_MAX = 500; -const ALLOWED_FORMATS = [ 'csv', 'json', 'text' ]; +const ALLOWED_FORMATS: OutputFormat[] = [ 'csv', 'json', 'table' ]; const DEFAULT_POLLING_DELAY_IN_SECONDS = 30; const MIN_POLLING_DELAY_IN_SECONDS = 5; const MAX_POLLING_DELAY_IN_SECONDS = 300; @@ -186,11 +186,11 @@ void command( { appContext: true, appQuery, envContext: true, - format: true, + format: false, module: 'slowlogs', } ) .option( 'limit', 'The maximum number of log lines', 500 ) - .option( 'format', 'Output the log lines in CSV or JSON format', 'text' ) + .option( 'format', 'Output the log lines in CSV or JSON format', 'table' ) .examples( [ { description: 'Get the most recent app slowlogs', diff --git a/src/lib/app-slowlogs/types.ts b/src/lib/app-slowlogs/types.ts index a3253e3a9..73d25f6e0 100644 --- a/src/lib/app-slowlogs/types.ts +++ b/src/lib/app-slowlogs/types.ts @@ -11,17 +11,13 @@ export interface DefaultOptions { }; } -export type SlowlogFormats = 'ids' | 'json' | 'csv'; +export type SlowlogFormats = 'json' | 'csv' | 'table'; -type Stringable = - | string - | { - toString: () => string; - }; +type Stringable = string | { toString: () => string }; export interface GetSlowLogsOptions extends DefaultOptions { limit: number; - format: 'ids' | 'json' | 'csv'; + format: 'table' | 'json' | 'csv'; } export interface GetRecentSlowlogsResponse { diff --git a/src/lib/cli/format.ts b/src/lib/cli/format.ts index 6697477c4..77c626515 100644 --- a/src/lib/cli/format.ts +++ b/src/lib/cli/format.ts @@ -9,21 +9,19 @@ export interface Tuple { value: string; } -type Stringable = - | string - | { - toString: () => string; - }; +type Stringable = string | { toString: () => string }; + +export type OutputFormat = 'keyValue' | 'ids' | 'json' | 'csv' | 'table'; export function formatData( data: Tuple[], format: 'keyValue' ): string; -export function formatData( data: Record< string, Stringable >[], format: 'table' ): string; export function formatData( data: Record< string, unknown >[], format: 'ids' | 'json' | 'csv' ): string; +export function formatData( data: Record< string, Stringable >[], format: OutputFormat ): string; export function formatData( data: Record< string, unknown >[] | Tuple[], - format: 'keyValue' | 'ids' | 'json' | 'csv' | 'table' + format: OutputFormat ): string { if ( ! data.length ) { return '';