Skip to content

Commit 2665054

Browse files
Mark cli args as non_exhaustive and warn that cli mod doesnt provide SemVer guarantees. (#517)
* docs: Add warnings that cli mod does not provide semver guarantees * feat: Mark cli args as non_exhaustive * docs: Update cli warning
1 parent a8ce6d9 commit 2665054

File tree

5 files changed

+56
-19
lines changed

5 files changed

+56
-19
lines changed

cargo-espflash/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ enum Commands {
109109
}
110110

111111
#[derive(Debug, Args)]
112+
#[non_exhaustive]
112113
struct BuildArgs {
113114
/// Binary to build and flash
114115
#[arg(long)]
@@ -147,26 +148,25 @@ struct BuildArgs {
147148

148149
/// Erase named partitions based on provided partition table
149150
#[derive(Debug, Args)]
151+
#[non_exhaustive]
150152
pub struct ErasePartsArgs {
151153
/// Connection configuration
152154
#[clap(flatten)]
153155
pub connect_args: ConnectArgs,
154-
155156
/// Labels of the partitions to be erased
156157
#[arg(value_name = "LABELS", value_delimiter = ',')]
157158
pub erase_parts: Vec<String>,
158-
159159
/// Input partition table
160160
#[arg(long, value_name = "FILE")]
161161
pub partition_table: Option<PathBuf>,
162-
163162
/// Specify a (binary) package within a workspace which may provide a partition table
164163
#[arg(long)]
165164
pub package: Option<String>,
166165
}
167166

168167
/// Build and flash an application to a target device
169168
#[derive(Debug, Args)]
169+
#[non_exhaustive]
170170
struct FlashArgs {
171171
#[clap(flatten)]
172172
build_args: BuildArgs,
@@ -177,11 +177,11 @@ struct FlashArgs {
177177
}
178178

179179
#[derive(Debug, Args)]
180+
#[non_exhaustive]
180181
struct SaveImageArgs {
181182
/// Image format to flash
182183
#[arg(long, value_enum)]
183184
pub format: Option<ImageFormatKind>,
184-
185185
#[clap(flatten)]
186186
build_args: BuildArgs,
187187
#[clap(flatten)]

espflash/README.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ Supports the **ESP32**, **ESP32-C2/C3/C6**, **ESP32-H2**, **ESP32-S2/S3**, and *
1111

1212
## Table of Contents
1313

14-
- [Installation](#installation)
15-
- [Usage](#usage)
16-
- [Permissions on Linux](#permissions-on-linux)
17-
- [Windows Subsystem for Linux](#windows-subsystem-for-linux)
18-
- [Cargo Runner](#cargo-runner)
19-
- [Configuration File](#configuration-file)
20-
- [Configuration examples](#configuration-examples)
21-
- [License](#license)
22-
- [Contribution](#contribution)
14+
- [espflash](#espflash)
15+
- [Table of Contents](#table-of-contents)
16+
- [Installation](#installation)
17+
- [Usage](#usage)
18+
- [Permissions on Linux](#permissions-on-linux)
19+
- [Windows Subsystem for Linux](#windows-subsystem-for-linux)
20+
- [Cargo Runner](#cargo-runner)
21+
- [Using `espflash` as a Library](#using-espflash-as-a-library)
22+
- [Configuration File](#configuration-file)
23+
- [Configuration Examples](#configuration-examples)
24+
- [License](#license)
25+
- [Contribution](#contribution)
2326

2427
## Installation
2528

@@ -93,7 +96,7 @@ Check your Linux distribution’s documentation for more information.
9396

9497
### Windows Subsystem for Linux
9598

96-
It is _not_ currently possible to use `cargo-espflash` from within WSL1. There are no plans to add support for WSL1 at this time.
99+
It is _not_ currently possible to use `espflash` from within WSL1. There are no plans to add support for WSL1 at this time.
97100

98101
It is also _not_ possible to flash chips using the built-in `USB_SERIAL_JTAG` peripheral when using WSL2, because resetting also resets `USB_SERIAL_JTAG` peripheral, which then disconnects the chip from WSL2. Chips _can_ be flashed via UART using WSL2, however.
99102

@@ -108,6 +111,25 @@ runner = "espflash flash --baud=921600 --monitor /dev/ttyUSB0"
108111

109112
With this configuration you can flash and monitor you application using `cargo run`.
110113

114+
## Using `espflash` as a Library
115+
116+
`espflash` can be used as a library in other applications:
117+
```toml
118+
espflash = { version = "2.1", default-features = false }
119+
```
120+
or `cargo add espflash --no-default-features`
121+
122+
> **Warning**
123+
> Note that the `cli` module does not provide SemVer guarantees.
124+
125+
We disable the `default-features` to opt-out the `cli` feature, which is enabled by default; you likely will not need any of these types or functions in your application so there’s no use pulling in the extra dependencies.
126+
127+
Just like when using `espflash` as an application, you can enable the raspberry feature to allow your dependent application to use the Raspberry Pi’s built-in UART:
128+
129+
```toml
130+
espflash = { version = "2.1", default-features = false, features = ["raspberry"] }
131+
```
132+
111133
## Configuration File
112134

113135
It's possible to specify a serial port and/or USB VID/PID values by setting them in a configuration file. The location of this file differs based on your operating system:

espflash/src/bin/espflash.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,21 @@ enum Commands {
8787

8888
/// Erase named partitions based on provided partition table
8989
#[derive(Debug, Args)]
90+
#[non_exhaustive]
9091
pub struct ErasePartsArgs {
9192
/// Connection configuration
9293
#[clap(flatten)]
9394
pub connect_args: ConnectArgs,
94-
9595
/// Labels of the partitions to be erased
9696
#[arg(value_name = "LABELS", value_delimiter = ',')]
9797
pub erase_parts: Vec<String>,
98-
9998
/// Input partition table
10099
#[arg(long, value_name = "FILE")]
101100
pub partition_table: Option<PathBuf>,
102101
}
103102

104103
#[derive(Debug, Args)]
104+
#[non_exhaustive]
105105
struct FlashArgs {
106106
/// Connection configuration
107107
#[clap(flatten)]
@@ -117,6 +117,7 @@ struct FlashArgs {
117117
}
118118

119119
#[derive(Debug, Args)]
120+
#[non_exhaustive]
120121
struct SaveImageArgs {
121122
/// ELF image to flash
122123
image: PathBuf,
@@ -133,6 +134,7 @@ struct SaveImageArgs {
133134

134135
/// Writes a binary file to a specific address in the chip's flash
135136
#[derive(Debug, Args)]
137+
#[non_exhaustive]
136138
struct WriteBinArgs {
137139
/// Address at which to write the binary file
138140
#[arg(value_parser = parse_uint32)]

espflash/src/cli/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
//! and [espflash] command-line applications, and are likely not of much use
55
//! otherwise.
66
//!
7+
//! Important note: The cli module DOES NOT provide SemVer guarantees,
8+
//! feel free to opt-out by disabling the default `cli` feature.
9+
//!
710
//! [cargo-espflash]: https://crates.io/crates/cargo-espflash
811
//! [espflash]: https://crates.io/crates/espflash
912
@@ -45,6 +48,7 @@ mod serial;
4548

4649
/// Establish a connection with a target device
4750
#[derive(Debug, Args)]
51+
#[non_exhaustive]
4852
pub struct ConnectArgs {
4953
/// Baud rate at which to communicate with target device
5054
#[arg(short = 'b', long, env = "ESPFLASH_BAUD")]
@@ -73,13 +77,15 @@ pub struct ConnectArgs {
7377

7478
/// Generate completions for the given shell
7579
#[derive(Debug, Args)]
80+
#[non_exhaustive]
7681
pub struct CompletionsArgs {
7782
/// Shell to generate completions for.
7883
pub shell: Shell,
7984
}
8085

8186
/// Erase entire flash of target device
8287
#[derive(Debug, Args)]
88+
#[non_exhaustive]
8389
pub struct EraseFlashArgs {
8490
/// Connection configuration
8591
#[clap(flatten)]
@@ -88,6 +94,7 @@ pub struct EraseFlashArgs {
8894

8995
/// Erase specified region of flash
9096
#[derive(Debug, Args)]
97+
#[non_exhaustive]
9198
pub struct EraseRegionArgs {
9299
/// Connection configuration
93100
#[clap(flatten)]
@@ -102,6 +109,7 @@ pub struct EraseRegionArgs {
102109

103110
/// Configure communication with the target device's flash
104111
#[derive(Debug, Args)]
112+
#[non_exhaustive]
105113
pub struct FlashConfigArgs {
106114
/// Flash frequency
107115
#[arg(short = 'f', long, value_name = "FREQ", value_enum)]
@@ -116,6 +124,7 @@ pub struct FlashConfigArgs {
116124

117125
/// Flash an application to a target device
118126
#[derive(Debug, Args)]
127+
#[non_exhaustive]
119128
#[group(skip)]
120129
pub struct FlashArgs {
121130
/// Path to a binary (.bin) bootloader file
@@ -155,6 +164,7 @@ pub struct FlashArgs {
155164

156165
/// Operations for partitions tables
157166
#[derive(Debug, Args)]
167+
#[non_exhaustive]
158168
pub struct PartitionTableArgs {
159169
/// Optional output file name, if unset will output to stdout
160170
#[arg(short = 'o', long, value_name = "FILE")]
@@ -172,6 +182,7 @@ pub struct PartitionTableArgs {
172182

173183
/// Save the image to disk instead of flashing to device
174184
#[derive(Debug, Args)]
185+
#[non_exhaustive]
175186
#[group(skip)]
176187
pub struct SaveImageArgs {
177188
/// Custom bootloader for merging
@@ -201,6 +212,7 @@ pub struct SaveImageArgs {
201212

202213
/// Open the serial monitor without flashing
203214
#[derive(Debug, Args)]
215+
#[non_exhaustive]
204216
pub struct MonitorArgs {
205217
/// Connection configuration
206218
#[clap(flatten)]

espflash/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@
2525
//! [espflash] can also be used as a library:
2626
//!
2727
//! ```toml
28-
//! espflash = { version = "2.0", default-features = false }
28+
//! espflash = { version = "2.1", default-features = false }
2929
//! ```
3030
//!
3131
//! We add `default-features` here to disable the `cli` feature, which is
32-
//! enabled by default; you likely will not need any of these types or functions
32+
//! enabled by default. Its important to note that the cli module does not
33+
//! provide SemVer guarantees. You likely will not need any of these types or functions
3334
//! in your application so there's no use pulling in the extra dependencies.
3435
//!
3536
//! Just like when using [espflash] as an application, you can enable the
3637
//! `raspberry` feature to allow your dependent application to use the Raspberry
3738
//! Pi's built-in UART:
3839
//!
3940
//! ```toml
40-
//! espflash = { version = "2.0", default-features = false, features = ["raspberry"] }
41+
//! espflash = { version = "2.1", default-features = false, features = ["raspberry"] }
4142
//! ```
4243
//!
4344
//! [espflash]: https://crates.io/crates/espflash

0 commit comments

Comments
 (0)