@@ -5,6 +5,18 @@ use crate::api::{Api, Dataset, FetchEventsOptions};
55use crate :: config:: Config ;
66use crate :: utils:: formatting:: Table ;
77
8+ /// Validate that max_rows is greater than 0
9+ fn validate_max_rows ( s : & str ) -> Result < usize , String > {
10+ let value = s
11+ . parse :: < usize > ( )
12+ . map_err ( |_| "invalid number" . to_owned ( ) ) ?;
13+ if value == 0 {
14+ Err ( "max-rows must be greater than 0" . to_owned ( ) )
15+ } else {
16+ Ok ( value)
17+ }
18+ }
19+
820/// Fields to fetch from the logs API
921const LOG_FIELDS : & [ & str ] = & [
1022 "sentry.item_id" ,
@@ -26,6 +38,7 @@ pub(super) struct ListLogsArgs {
2638 project : Option < String > ,
2739
2840 #[ arg( long = "max-rows" , default_value = "100" ) ]
41+ #[ arg( value_parser = validate_max_rows) ]
2942 #[ arg( help = "Maximum number of log entries to fetch and display (max 1000)." ) ]
3043 max_rows : usize ,
3144
@@ -43,7 +56,7 @@ pub(super) fn execute(args: ListLogsArgs) -> Result<()> {
4356 . as_ref ( )
4457 . or ( default_org. as_ref ( ) )
4558 . ok_or_else ( || {
46- anyhow:: anyhow!( "No organization specified. Use --org or set a default in config ." )
59+ anyhow:: anyhow!( "No organization specified. Please specify an organization using the --org argument ." )
4760 } ) ?
4861 . to_owned ( ) ;
4962 let project = args
@@ -98,15 +111,14 @@ fn execute_single_fetch(
98111 . add ( "Message" )
99112 . add ( "Trace" ) ;
100113
101- if let Some ( logs) = logs. get ( ..args. max_rows ) {
102- for log in logs {
103- let row = table. add_row ( ) ;
104- row. add ( & log. item_id )
105- . add ( & log. timestamp )
106- . add ( log. severity . as_deref ( ) . unwrap_or ( "" ) )
107- . add ( log. message . as_deref ( ) . unwrap_or ( "" ) )
108- . add ( log. trace . as_deref ( ) . unwrap_or ( "" ) ) ;
109- }
114+ let logs_to_show = & logs[ ..args. max_rows . min ( logs. len ( ) ) ] ;
115+ for log in logs_to_show {
116+ let row = table. add_row ( ) ;
117+ row. add ( & log. item_id )
118+ . add ( & log. timestamp )
119+ . add ( log. severity . as_deref ( ) . unwrap_or ( "" ) )
120+ . add ( log. message . as_deref ( ) . unwrap_or ( "" ) )
121+ . add ( log. trace . as_deref ( ) . unwrap_or ( "" ) ) ;
110122 }
111123
112124 if table. is_empty ( ) {
0 commit comments