@@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize};
1010use std:: collections:: HashMap ;
1111use std:: str:: FromStr ;
1212
13+ const MAX_OUTPUT_LINES : usize = 45 ;
14+
1315#[ derive( Debug , Serialize ) ]
1416struct PlaygroundCode < ' a > {
1517 channel : Channel ,
@@ -135,6 +137,7 @@ struct PlayResult {
135137fn run_code ( args : & Args , code : & str ) -> Result < String > {
136138 let mut errors = String :: new ( ) ;
137139
140+ let warnings = args. params . get ( "warn" ) . unwrap_or_else ( || & "false" ) ;
138141 let channel = args. params . get ( "channel" ) . unwrap_or_else ( || & "nightly" ) ;
139142 let mode = args. params . get ( "mode" ) . unwrap_or_else ( || & "debug" ) ;
140143 let edition = args. params . get ( "edition" ) . unwrap_or_else ( || & "2018" ) ;
@@ -168,23 +171,29 @@ fn run_code(args: &Args, code: &str) -> Result<String> {
168171
169172 let result: PlayResult = resp. json ( ) ?;
170173
171- let result = if result. success {
174+ let result = if * warnings == "true" {
175+ format ! ( "{}\n {}" , result. stderr, result. stdout)
176+ } else if result. success {
172177 result. stdout
173178 } else {
174179 result. stderr
175180 } ;
176181
177- Ok ( if result. len ( ) + errors. len ( ) > 1994 {
178- format ! (
179- "{}Output too large. Playground link: {}" ,
180- errors,
181- get_playground_link( args, code, & request) ?
182- )
183- } else if result. len ( ) == 0 {
184- format ! ( "{}compilation succeded." , errors)
185- } else {
186- format ! ( "{}```{}```" , errors, result)
187- } )
182+ let lines = result. lines ( ) . count ( ) ;
183+
184+ Ok (
185+ if result. len ( ) + errors. len ( ) > 1993 || lines > MAX_OUTPUT_LINES {
186+ format ! (
187+ "{}Output too large. Playground link: {}" ,
188+ errors,
189+ get_playground_link( args, code, & request) ?
190+ )
191+ } else if result. len ( ) == 0 {
192+ format ! ( "{}compilation succeded." , errors)
193+ } else {
194+ format ! ( "{}```\n {}```" , errors, result)
195+ } ,
196+ )
188197}
189198
190199fn get_playground_link ( args : & Args , code : & str , request : & PlaygroundCode ) -> Result < String > {
@@ -220,11 +229,12 @@ pub fn run(args: Args) -> Result<()> {
220229pub fn help ( args : Args , name : & str ) -> Result < ( ) > {
221230 let message = format ! (
222231 "Compile and run rust code. All code is executed on https://play.rust-lang.org.
223- ```?{} mode={{}} channel={{}} edition={{}} ``\u{200B} `code``\u{200B} ` ```
232+ ```?{} mode={{}} channel={{}} edition={{}} warn={{}} ``\u{200B} `code``\u{200B} ` ```
224233Optional arguments:
225234 \t mode: debug, release (default: debug)
226235 \t channel: stable, beta, nightly (default: nightly)
227236 \t edition: 2015, 2018 (default: 2018)
237+ \t warn: boolean flag to enable compilation warnings
228238 " ,
229239 name
230240 ) ;
0 commit comments