@@ -24,26 +24,24 @@ async function buildContext(program: Program, toolchain: string | undefined): Pr
24
24
rustc : "" ,
25
25
} ;
26
26
27
- toolchain = `+${ toolchain } ` ?? "" ;
28
-
29
27
await Promise . all ( [
30
- await exec . exec ( "rustc" , [ toolchain , "-V" ] , {
28
+ await exec . exec ( "rustc" , buildToolchainArguments ( toolchain , [ "-V" ] ) , {
31
29
silent : false ,
32
30
listeners : {
33
31
stdout : ( buffer : Buffer ) => {
34
32
return ( context . rustc = buffer . toString ( ) . trim ( ) ) ;
35
33
} ,
36
34
} ,
37
35
} ) ,
38
- await program . call ( [ toolchain , "-V" ] , {
36
+ await program . call ( buildToolchainArguments ( toolchain , [ "-V" ] ) , {
39
37
silent : false ,
40
38
listeners : {
41
39
stdout : ( buffer : Buffer ) => {
42
40
return ( context . cargo = buffer . toString ( ) . trim ( ) ) ;
43
41
} ,
44
42
} ,
45
43
} ) ,
46
- await program . call ( [ toolchain , "clippy" , "-V" ] , {
44
+ await program . call ( buildToolchainArguments ( toolchain , [ "clippy" , "-V" ] ) , {
47
45
silent : false ,
48
46
listeners : {
49
47
stdout : ( buffer : Buffer ) => {
@@ -57,7 +55,7 @@ async function buildContext(program: Program, toolchain: string | undefined): Pr
57
55
}
58
56
59
57
async function runClippy ( actionInput : input . ParsedInput , program : Program ) : Promise < ClippyResult > {
60
- const args = buildArgs ( actionInput ) ;
58
+ const args = buildClippyArguments ( actionInput ) ;
61
59
const outputParser = new OutputParser ( ) ;
62
60
63
61
const options : exec . ExecOptions = {
@@ -112,20 +110,29 @@ export async function run(actionInput: input.ParsedInput): Promise<void> {
112
110
}
113
111
}
114
112
115
- function buildArgs ( actionInput : input . ParsedInput ) : string [ ] {
116
- const args : string [ ] = [ ] ;
113
+ function buildToolchainArguments ( toolchain : string | undefined , after : string [ ] ) : string [ ] {
114
+ const args = [ ] ;
117
115
118
- // Toolchain selection MUST go first in any condition
119
- if ( actionInput . toolchain ) {
120
- args . push ( `+${ actionInput . toolchain } ` ) ;
116
+ if ( toolchain ) {
117
+ args . push ( `+${ toolchain } ` ) ;
121
118
}
122
119
123
- args . push ( "clippy" ) ;
120
+ args . push ( ...after ) ;
121
+
122
+ return args ;
123
+ }
124
124
125
- // `--message-format=json` should just right after the `cargo clippy`
126
- // because usually people are adding the `-- -D warnings` at the end
127
- // of arguments and it will mess up the output.
128
- args . push ( "--message-format=json" ) ;
125
+ function buildClippyArguments ( actionInput : input . ParsedInput ) : string [ ] {
126
+ // Toolchain selection MUST go first in any condition!
127
+ return buildToolchainArguments ( actionInput . toolchain , [
128
+ "clippy" ,
129
129
130
- return args . concat ( actionInput . args ) ;
130
+ // `--message-format=json` should just right after the `cargo clippy`
131
+ // because usually people are adding the `-- -D warnings` at the end
132
+ // of arguments and it will mess up the output.
133
+ "--message-format=json" ,
134
+
135
+ // and the rest
136
+ ...actionInput . args ,
137
+ ] ) ;
131
138
}
0 commit comments