diff --git a/__tests__/bin/vip-logs.js b/__tests__/bin/vip-logs.js index 2e2700294..971572068 100644 --- a/__tests__/bin/vip-logs.js +++ b/__tests__/bin/vip-logs.js @@ -329,7 +329,7 @@ describe( 'getLogs', () => { expect( exit.withError ).toHaveBeenCalledTimes( 1 ); expect( exit.withError ).toHaveBeenCalledWith( - `Invalid limit: ${ limit }. It should be a number between 1 and 5000.` + `Invalid limit: ${ limit }. Set the limit to an integer between 1 and 5000.` ); expect( logsLib.getRecentLogs ).not.toHaveBeenCalled(); diff --git a/__tests__/bin/vip-slowlogs.js b/__tests__/bin/vip-slowlogs.js index 38100efeb..2f26b3954 100644 --- a/__tests__/bin/vip-slowlogs.js +++ b/__tests__/bin/vip-slowlogs.js @@ -354,7 +354,7 @@ describe( 'getSlowlogs', () => { expect( exit.withError ).toHaveBeenCalledTimes( 1 ); expect( exit.withError ).toHaveBeenCalledWith( - `Invalid limit: ${ limit }. It should be a number between 1 and 5000.` + `Invalid limit: ${ limit }. Set the limit to an integer between 1 and 5000.` ); expect( slowlogsLib.getRecentSlowlogs ).not.toHaveBeenCalled(); diff --git a/src/bin/vip-logs.js b/src/bin/vip-logs.js index 79047283d..7b0ff786a 100755 --- a/src/bin/vip-logs.js +++ b/src/bin/vip-logs.js @@ -23,6 +23,10 @@ const MAX_POLLING_DELAY_IN_SECONDS = 300; * @param {string[]} arg */ export async function getLogs( arg, opt ) { + opt.type ??= 'app'; + opt.limit ??= LIMIT_DEFAULT; + opt.format ??= 'table'; + validateInputs( opt.type, opt.limit, opt.format ); const trackingParams = getBaseTrackingParams( opt ); @@ -188,10 +192,6 @@ function printLogs( logs, format ) { * @param {string} format */ export function validateInputs( type, limit, format ) { - if ( limit === undefined ) { - limit = LIMIT_DEFAULT; - } - if ( ! ALLOWED_TYPES.includes( type ) ) { exit.withError( `Invalid type: ${ type }. The supported types are: ${ ALLOWED_TYPES.join( ', ' ) }.` @@ -206,7 +206,7 @@ export function validateInputs( type, limit, format ) { if ( ! Number.isInteger( limit ) || limit < LIMIT_MIN || limit > logsLib.LIMIT_MAX ) { exit.withError( - `Invalid limit: ${ limit }. It should be a number between ${ LIMIT_MIN } and ${ logsLib.LIMIT_MAX }.` + `Invalid limit: ${ limit }. Set the limit to an integer between ${ LIMIT_MIN } and ${ logsLib.LIMIT_MAX }.` ); } } @@ -232,31 +232,37 @@ command( { envContext: true, module: 'logs', } ) - .option( 'type', 'The type of logs to be returned: "app" or "batch"', 'app' ) + .option( + 'type', + 'Specify the type of Runtime Logs to retrieve. Accepts "batch" (only valid for WordPress environments).', + 'app' + ) // The default limit is set manually in the validateInputs function to address validation issues, avoiding incorrect replacement of the default value. - .option( 'limit', `The maximum number of log lines (defaults to ${ LIMIT_DEFAULT })` ) - .option( 'follow', 'Keep fetching new logs as they are generated' ) - .option( 'format', 'Output the log lines in CSV or JSON format', 'table' ) + .option( + 'limit', + `The maximum number of entries to return. Accepts an integer value between 1 and 5000 (defaults to ${ LIMIT_DEFAULT }).` + ) + .option( 'follow', 'Output new entries as they are generated.' ) + .option( 'format', 'Render output in a particular format. Accepts “csv”, and “json”.', 'table' ) .examples( [ { - usage: 'vip @mysite.production logs', - description: 'Get the most recent app logs', - }, - { - usage: 'vip @mysite.production logs --type batch', - description: 'Get the most recent batch logs', + usage: 'vip @example-app.production logs', + description: + 'Retrieve up to 500 of the most recent entries of application Runtime Logs from web containers.', }, { - usage: 'vip @mysite.production logs --limit 100', - description: 'Get the most recent 100 log entries', + usage: 'vip @example-app.production logs --type=batch', + description: + 'Retrieve up to 500 of the most recent entries generated by cron tasks or WP-CLI commands from batch containers.', }, { - usage: 'vip @mysite.production logs --limit 100 --format csv', - description: 'Get the most recent 100 log entries formatted as comma-separated values (CSV)', + usage: 'vip @example-app.production logs --limit=100', + description: 'Retrieve up to 100 of the most recent entries of application logs.', }, { - usage: 'vip @mysite.production logs --limit 100 --format json', - description: 'Get the most recent 100 log entries formatted as JSON', + usage: 'vip @example-app.production logs --type=batch --limit=800 --format=csv', + description: + 'Retrieve up to 800 of the most recent entries of batch logs and output them in CSV format.', }, ] ) .argv( process.argv, getLogs ); diff --git a/src/bin/vip-slowlogs.ts b/src/bin/vip-slowlogs.ts index 39f67b96c..4b84f897c 100755 --- a/src/bin/vip-slowlogs.ts +++ b/src/bin/vip-slowlogs.ts @@ -28,6 +28,7 @@ const exampleUsage = 'vip @example-app.develop slowlogs'; const baseUsage = 'vip slowlogs'; export async function getSlowlogs( arg: string[], opt: GetSlowLogsOptions ): Promise< void > { + opt.format ??= 'table'; validateInputs( opt.limit, opt.format ); const trackingParams = getBaseTrackingParams( opt ); @@ -165,7 +166,7 @@ export function validateInputs( limit: number, format: SlowlogFormats ): void { if ( ! Number.isInteger( limit ) || limit < LIMIT_MIN || limit > slowlogsLib.LIMIT_MAX ) { exit.withError( - `Invalid limit: ${ limit }. It should be a number between ${ LIMIT_MIN } and ${ slowlogsLib.LIMIT_MAX }.` + `Invalid limit: ${ limit }. Set the limit to an integer between ${ LIMIT_MIN } and ${ slowlogsLib.LIMIT_MAX }.` ); } } @@ -193,8 +194,12 @@ void command( { module: 'slowlogs', usage: baseUsage, } ) - .option( 'limit', 'The maximum number of log entries', 500 ) - .option( 'format', 'Output the log entries in CSV or JSON format', 'table' ) + .option( + 'limit', + 'Set the maximum number of log entries. Accepts an integer value between 1 and 500.', + 500 + ) + .option( 'format', 'Render output in a particular format. Accepts “csv”, and “json”.', 'table' ) .examples( [ { description: diff --git a/src/bin/vip.js b/src/bin/vip.js index 0a353c7a3..07980f2b5 100755 --- a/src/bin/vip.js +++ b/src/bin/vip.js @@ -36,7 +36,7 @@ const runCmd = async function () { .command( 'dev-env', 'Create and manage VIP Local Development Environments.' ) .command( 'export', 'Export a copy of data associated with an environment.' ) .command( 'import', 'Import media or SQL database files to an environment.' ) - .command( 'logs', 'Get logs from your VIP applications' ) + .command( 'logs', 'Retrieve Runtime Logs from an environment.' ) .command( 'search-replace', 'Search for a string in a local SQL file and replace it with a new string.' diff --git a/src/lib/cli/command.js b/src/lib/cli/command.js index e5d0afbe0..5d3138f4f 100644 --- a/src/lib/cli/command.js +++ b/src/lib/cli/command.js @@ -603,7 +603,8 @@ export default function ( opts ) { if ( _opts.format ) { args.option( 'format', - 'Render output in a particular format. Accepts "table" (default), "csv", and "json".' + 'Render output in a particular format. Accepts “csv”, and “json”.', + 'table' ); }