Skip to content

Commit

Permalink
Merge pull request #2093 from Automattic/hotfix/validate-logs-limit
Browse files Browse the repository at this point in the history
Fix --limit arg handling in vip logs command
  • Loading branch information
ariskataoka authored Nov 13, 2024
2 parents 4020878 + 2f7ad73 commit 16d0337
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/bin/vip-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { trackEvent } from '../lib/tracker';

const LIMIT_MIN = 1;
const LIMIT_MAX = 5000;
const LIMIT_DEFAULT = 500;
const ALLOWED_TYPES = [ 'app', 'batch' ];
const ALLOWED_FORMATS = [ 'csv', 'json', 'table' ];
const DEFAULT_POLLING_DELAY_IN_SECONDS = 30;
Expand Down Expand Up @@ -161,6 +162,10 @@ 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( ', ' ) }.`
Expand Down Expand Up @@ -202,7 +207,8 @@ command( {
module: 'logs',
} )
.option( 'type', 'The type of logs to be returned: "app" or "batch"', 'app' )
.option( 'limit', 'The maximum number of log lines', 500 )
// 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' )
.examples( [
Expand Down

0 comments on commit 16d0337

Please sign in to comment.