Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update thevip logs command to follow the VIP-CLI style guide #2089

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion __tests__/bin/vip-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/bin/vip-slowlogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
42 changes: 25 additions & 17 deletions src/bin/vip-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }.`
);
}
}
Expand All @@ -232,31 +232,39 @@ 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) or "app" (default).'
yolih marked this conversation as resolved.
Show resolved Hide resolved
)
sjinks marked this conversation as resolved.
Show resolved Hide resolved
// 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',
`Set a maximum number of entries to retrieve. Accepts an integer value between 1 and 5000 (defaults to ${ LIMIT_DEFAULT }).`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`Set a maximum number of entries to retrieve. Accepts an integer value between 1 and 5000 (defaults to ${ LIMIT_DEFAULT }).`
`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 “table” (default), “csv”, and “json”.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we consistently surrounding the accepted options with the stylized double quotes through all the CLI commands?

)
.examples( [
{
usage: 'vip @mysite.production logs',
description: 'Get the most recent app logs',
usage: 'vip @example-app.production logs',
description:
'Retrieve up to 500 of the most recent entries of application Runtime Logs from web containers.',
sjinks marked this conversation as resolved.
Show resolved Hide resolved
},
{
usage: 'vip @mysite.production logs --type batch',
description: 'Get the most recent batch logs',
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',
description: 'Get the most recent 100 log entries',
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 csv',
description: 'Get the most recent 100 log entries formatted as comma-separated values (CSV)',
},
{
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 );
13 changes: 10 additions & 3 deletions src/bin/vip-slowlogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,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 }.`
);
}
}
Expand Down Expand Up @@ -193,8 +193,15 @@ 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 “table” (default), “csv”, and “json”.'
)
.examples( [
{
description:
Expand Down
2 changes: 1 addition & 1 deletion src/bin/vip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', 'Perform search and replace tasks on files' )
.command( 'slowlogs', 'Retrieve MySQL slow query logs from an environment.' )
.command( 'db', "Access an environment's database." )
Expand Down
2 changes: 1 addition & 1 deletion src/lib/cli/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ 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 table (default), csv, and json.'
);
}

Expand Down