@@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize};
10
10
use std:: collections:: HashMap ;
11
11
use std:: str:: FromStr ;
12
12
13
+ const MAX_OUTPUT_LINES : usize = 45 ;
14
+
13
15
#[ derive( Debug , Serialize ) ]
14
16
struct PlaygroundCode < ' a > {
15
17
channel : Channel ,
@@ -135,6 +137,7 @@ struct PlayResult {
135
137
fn run_code ( args : & Args , code : & str ) -> Result < String > {
136
138
let mut errors = String :: new ( ) ;
137
139
140
+ let warnings = args. params . get ( "warn" ) . unwrap_or_else ( || & "false" ) ;
138
141
let channel = args. params . get ( "channel" ) . unwrap_or_else ( || & "nightly" ) ;
139
142
let mode = args. params . get ( "mode" ) . unwrap_or_else ( || & "debug" ) ;
140
143
let edition = args. params . get ( "edition" ) . unwrap_or_else ( || & "2018" ) ;
@@ -168,23 +171,29 @@ fn run_code(args: &Args, code: &str) -> Result<String> {
168
171
169
172
let result: PlayResult = resp. json ( ) ?;
170
173
171
- let result = if result. success {
174
+ let result = if * warnings == "true" {
175
+ format ! ( "{}\n {}" , result. stderr, result. stdout)
176
+ } else if result. success {
172
177
result. stdout
173
178
} else {
174
179
result. stderr
175
180
} ;
176
181
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
+ )
188
197
}
189
198
190
199
fn get_playground_link ( args : & Args , code : & str , request : & PlaygroundCode ) -> Result < String > {
@@ -220,11 +229,12 @@ pub fn run(args: Args) -> Result<()> {
220
229
pub fn help ( args : Args , name : & str ) -> Result < ( ) > {
221
230
let message = format ! (
222
231
"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} ` ```
224
233
Optional arguments:
225
234
\t mode: debug, release (default: debug)
226
235
\t channel: stable, beta, nightly (default: nightly)
227
236
\t edition: 2015, 2018 (default: 2018)
237
+ \t warn: boolean flag to enable compilation warnings
228
238
" ,
229
239
name
230
240
) ;
0 commit comments