1
+ use cargo_config:: has_build_std;
1
2
use cargo_metadata:: Message ;
2
3
use clap:: { App , Arg , SubCommand } ;
3
4
use error:: Error ;
4
5
use espflash:: { Config , Flasher , PartitionTable } ;
5
6
use miette:: { IntoDiagnostic , Result , WrapErr } ;
7
+ use monitor:: monitor;
8
+ use package_metadata:: CargoEspFlashMeta ;
6
9
use serial:: { BaudRate , SerialPort } ;
7
10
use std:: {
8
11
fs,
@@ -11,13 +14,11 @@ use std::{
11
14
string:: ToString ,
12
15
} ;
13
16
14
- use cargo_config:: has_build_std;
15
- use monitor:: monitor;
16
-
17
17
mod cargo_config;
18
18
mod error;
19
19
mod line_endings;
20
20
mod monitor;
21
+ mod package_metadata;
21
22
22
23
fn main ( ) -> Result < ( ) > {
23
24
let mut app = App :: new ( env ! ( "CARGO_PKG_NAME" ) )
@@ -100,6 +101,7 @@ fn main() -> Result<()> {
100
101
} ;
101
102
102
103
let config = Config :: load ( ) ;
104
+ let metadata = CargoEspFlashMeta :: load ( "Cargo.toml" ) ?;
103
105
104
106
// The serial port must be specified, either as a command-line argument or in
105
107
// the cargo configuration file. In the case that both have been provided the
@@ -158,7 +160,10 @@ fn main() -> Result<()> {
158
160
159
161
// If the '--bootloader' option is provided, load the binary file at the
160
162
// specified path.
161
- let bootloader = if let Some ( path) = matches. value_of ( "bootloader" ) {
163
+ let bootloader = if let Some ( path) = matches
164
+ . value_of ( "bootloader" )
165
+ . or_else ( || metadata. bootloader . as_deref ( ) )
166
+ {
162
167
let path = fs:: canonicalize ( path) . into_diagnostic ( ) ?;
163
168
let data = fs:: read ( path) . into_diagnostic ( ) ?;
164
169
Some ( data)
@@ -168,7 +173,10 @@ fn main() -> Result<()> {
168
173
169
174
// If the '--partition-table' option is provided, load the partition table from
170
175
// the CSV at the specified path.
171
- let partition_table = if let Some ( path) = matches. value_of ( "partition_table" ) {
176
+ let partition_table = if let Some ( path) = matches
177
+ . value_of ( "partition_table" )
178
+ . or_else ( || metadata. partition_table . as_deref ( ) )
179
+ {
172
180
let path = fs:: canonicalize ( path) . into_diagnostic ( ) ?;
173
181
let data = fs:: read_to_string ( path) . into_diagnostic ( ) ?;
174
182
let table = PartitionTable :: try_from_str ( data) ?;
0 commit comments