@@ -4,7 +4,7 @@ use std::{
44 process:: Command ,
55} ;
66
7- use anyhow:: { bail , ensure , Context as _, Result } ;
7+ use anyhow:: { Context as _, Result , bail , ensure } ;
88use clap:: { Args , Subcommand } ;
99use esp_metadata:: Chip ;
1010
@@ -117,49 +117,33 @@ pub fn run_elfs(args: RunElfsArgs) -> Result<()> {
117117 Ok ( ( ) )
118118}
119119
120- pub fn run_example ( args : ExamplesArgs , examples : Vec < Metadata > , package_path : & Path ) -> Result < ( ) > {
121- // Determine the appropriate build target for the given package and chip:
122- let target = args. package . target_triple ( & args. chip ) ?;
123-
124- // Filter the examples down to only the binary we're interested in, assuming it
125- // actually supports the specified chip:
126- let mut found_one = false ;
127- for example in examples. iter ( ) . filter ( |ex| ex. matches ( & args. example ) ) {
128- found_one = true ;
129- crate :: execute_app (
130- package_path,
131- args. chip ,
132- target,
133- example,
134- CargoAction :: Run ,
135- 1 ,
136- args. debug ,
137- ) ?;
138- }
139-
140- ensure ! (
141- found_one,
142- "Example not found or unsupported for {}" ,
143- args. chip
144- ) ;
145-
146- Ok ( ( ) )
147- }
148-
149120pub fn run_examples (
150121 args : ExamplesArgs ,
151122 examples : Vec < Metadata > ,
152123 package_path : & Path ,
153124) -> Result < ( ) > {
125+ let mut examples = examples;
126+
154127 // Determine the appropriate build target for the given package and chip:
155128 let target = args. package . target_triple ( & args. chip ) ?;
156129
157- // Filter the examples down to only the binaries we're interested in
158- let mut examples: Vec < Metadata > = examples
159- . iter ( )
160- . filter ( |ex| ex. supports_chip ( args. chip ) )
161- . cloned ( )
162- . collect ( ) ;
130+ let single_example = args. example . is_some ( ) ;
131+
132+ // Filter the examples down to only the binaries supported by the given chip
133+ examples. retain ( |ex| ex. supports_chip ( args. chip ) ) ;
134+
135+ // User requested to run exactly one example
136+ if single_example {
137+ // Filter the examples down to only the binary we're interested in
138+ examples. retain ( |ex| ex. matches ( & args. example ) ) ;
139+
140+ ensure ! (
141+ examples. len( ) == 1 ,
142+ "Example not found or unsupported for {}" ,
143+ args. chip
144+ ) ;
145+ }
146+
163147 examples. sort_by_key ( |ex| ex. tag ( ) ) ;
164148
165149 let console = console:: Term :: stdout ( ) ;
0 commit comments