Skip to content

Commit 41ceb32

Browse files
committed
chore(cli): prepare for publishing
1 parent 1ac5a98 commit 41ceb32

File tree

6 files changed

+54
-43
lines changed

6 files changed

+54
-43
lines changed

Cargo.lock

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stm32cubeprogrammer-cli/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ bpaf = { version = "0.9", features = ["derive"] }
1515
env_logger = "0.11.5"
1616
indicatif = "0.17.9"
1717
indicatif-log-bridge = "0.2.3"
18-
stm32cubeprogrammer = { path = "../stm32cubeprogrammer", features = [
19-
"serde",
20-
"validations",
21-
] }
18+
stm32cubeprogrammer = { version = "0.1.0", features = ["serde", "validations"] }
2219
dotenvy.workspace = true
2320
log.workspace = true
2421
anyhow = "1.0.94"

stm32cubeprogrammer-cli/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ This CLI aims to provide a simple interface for setting up stm32 targets.
1111
- Resetting target
1212

1313
All commands above can be combined in a single command line invocation by chaining them.
14-
1514
If you need other commands, feel free to open an issue or a pull request. :smile:
1615

1716
## Example usage:
@@ -26,7 +25,7 @@ You can also pass the directory to the STM32CubeProgrammer installation using th
2625
```sh
2726
STM32_CUBE_PROGRAMMER_DIR=`installation_dir` stm32cubeprogrammer-cli reset
2827
```
29-
You can chain the different supported commands.
28+
You can chain multiple commands together.
3029
```sh
3130
STM32_CUBE_PROGRAMMER_DIR=`installation_dir` stm32cubeprogrammer-cli unprotect reset flash-hex `path_to_hex_file` protect
3231
```
@@ -36,10 +35,14 @@ Use the `--list` flag to list available probes.
3635
stm32cubeprogrammer-cli --stm32-cube-programmer-dir `installation_dir` --list
3736
```
3837

39-
Use `--help` to see all available options.
38+
Use `--help` to see all supported commands and options (or see [`crate::parse::Options`])
4039
```sh
4140
stm32cubeprogrammer-cli --help
4241
```
42+
## CLI output
43+
The CLI outputs a JSON object (see [`crate::output::Output`]) which contains information about the selected probe, general information about the target, and the output of each command.
44+
The output is printed to stdout.
45+
4346
## Requirements
4447
There needs to be a Stm32CubeProgrammer installation on your system. The crates are tested using Stm32CubeProgrammer version 2.18.0.
4548

stm32cubeprogrammer-cli/src/main.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//! - Resetting target
1010
//!
1111
//! All commands above can be combined in a single command line invocation by chaining them.
12-
//!
1312
//! If you need other commands, feel free to open an issue or a pull request. :smile:
1413
//!
1514
//! # Example usage:
@@ -24,7 +23,7 @@
2423
//! ```sh
2524
//! STM32_CUBE_PROGRAMMER_DIR=`installation_dir` stm32cubeprogrammer-cli reset
2625
//! ```
27-
//! You can chain the different supported commands.
26+
//! You can chain multiple commands together.
2827
//! ```sh
2928
//! STM32_CUBE_PROGRAMMER_DIR=`installation_dir` stm32cubeprogrammer-cli unprotect reset flash-hex `path_to_hex_file` protect
3029
//! ```
@@ -34,10 +33,14 @@
3433
//! stm32cubeprogrammer-cli --stm32-cube-programmer-dir `installation_dir` --list
3534
//! ```
3635
//!
37-
//! Use `--help` to see all available options.
36+
//! Use `--help` to see all supported commands and options (or see [`crate::parse::Options`])
3837
//! ```sh
3938
//! stm32cubeprogrammer-cli --help
4039
//! ```
40+
//! # CLI output
41+
//! The CLI outputs a JSON object (see [`crate::output::Output`]) which contains information about the selected probe, general information about the target, and the output of each command.
42+
//! The output is printed to stdout.
43+
//!
4144
//! # Requirements
4245
//! There needs to be a Stm32CubeProgrammer installation on your system. The crates are tested using Stm32CubeProgrammer version 2.18.0.
4346
//!
@@ -264,7 +267,7 @@ fn main_inner() -> Result<crate::output::Output, anyhow::Error> {
264267
if options
265268
.target_commands
266269
.iter()
267-
.any(|command| matches!(command, parse::TargetCommand::UpdateBleStack(_)))
270+
.any(|command| matches!(command, parse::TargetCommand::BleUpdate(_)))
268271
&& !programmer_connection
269272
.connection()?
270273
.general_information()
@@ -310,7 +313,7 @@ fn main_inner() -> Result<crate::output::Output, anyhow::Error> {
310313

311314
output::CommandOutput::FlashHex { file }
312315
}
313-
parse::TargetCommand::UpdateBleStack(ble_stack_info) => {
316+
parse::TargetCommand::BleUpdate(ble_stack_info) => {
314317
log::info!("Update BLE stack: {}", ble_stack_info);
315318

316319
display_handler
@@ -363,7 +366,7 @@ fn main_inner() -> Result<crate::output::Output, anyhow::Error> {
363366
.unwrap_or(output::BleStackUpdated::NotUpdated),
364367
}
365368
}
366-
parse::TargetCommand::BleStackInfo { compare } => {
369+
parse::TargetCommand::BleInfo { compare } => {
367370
display_handler
368371
.lock()
369372
.unwrap()

stm32cubeprogrammer-cli/src/output.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use std::env::ArgsOs;
44
#[derive(Debug, Serialize)]
55
#[serde(rename_all = "camelCase")]
66
pub struct Output {
7-
schema_version: String,
8-
args: String,
9-
cube_programmer_dir: std::path::PathBuf,
10-
connected_probes: Option<Vec<stm32cubeprogrammer::probe::Serial>>,
11-
selected_probe: Option<stm32cubeprogrammer::probe::Serial>,
12-
general_information: Option<stm32cubeprogrammer::api_types::GeneralInformation>,
13-
command_output: Option<Vec<CommandOutput>>,
7+
pub schema_version: String,
8+
pub args: String,
9+
pub cube_programmer_dir: std::path::PathBuf,
10+
pub connected_probes: Option<Vec<stm32cubeprogrammer::probe::Serial>>,
11+
pub selected_probe: Option<stm32cubeprogrammer::probe::Serial>,
12+
pub general_information: Option<stm32cubeprogrammer::api_types::GeneralInformation>,
13+
pub command_output: Option<Vec<CommandOutput>>,
1414
}
1515

1616
impl Output {

stm32cubeprogrammer-cli/src/parse.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bpaf::*;
22
use stm32cubeprogrammer::utility::HexAddress;
33

44
#[derive(Debug, Clone, Bpaf)]
5-
#[bpaf(options)]
5+
#[bpaf(options, version)]
66
/// Overall arguments for CLI
77
/// Note: Be careful with duplicate short or long flag names in the subcommands and the parent struct
88
pub struct Options {
@@ -58,11 +58,11 @@ pub enum TargetCommand {
5858

5959
#[bpaf(command, adjacent)]
6060
/// Update the BLE stack on the target
61-
UpdateBleStack(#[bpaf(external(ble_stack_info))] BleStackInfo),
61+
BleUpdate(#[bpaf(external(ble_stack_info))] BleStackInfo),
6262

63-
/// Read BLE stack information
63+
/// Read BLE stack information from the target and optionally compare the target version with a given version
6464
#[bpaf(command, adjacent)]
65-
BleStackInfo {
65+
BleInfo {
6666
#[bpaf(long, fallback(None))]
6767
/// The flash address in format 0x123 or 0X123 where file should be written
6868
compare: Option<stm32cubeprogrammer::fus::Version>,
@@ -235,24 +235,13 @@ mod test {
235235

236236
#[test]
237237
fn parse_multi() {
238+
std::env::set_var("STM32_CUBE_PROGRAMMER_DIR", "some/dir");
239+
240+
let command =
241+
"unprotect ble-update --file stack.bin --address 0x123 flash-bin --file app.bin --address 0x456 protect reset";
242+
238243
let value = options()
239-
.run_inner(&[
240-
"--stm32-cube-programmer-dir",
241-
"some/dir",
242-
"unprotect",
243-
"update-ble-stack",
244-
"--file",
245-
"stack.bin",
246-
"--address",
247-
"0x123",
248-
"flash-bin",
249-
"--file",
250-
"app.bin",
251-
"--address",
252-
"0x456",
253-
"protect",
254-
"reset",
255-
])
244+
.run_inner(command.split(' ').collect::<Vec<_>>().as_slice())
256245
.unwrap();
257246

258247
println!("{:?}", value);
@@ -261,7 +250,7 @@ mod test {
261250
value.target_commands,
262251
vec![
263252
TargetCommand::Unprotect,
264-
TargetCommand::UpdateBleStack(BleStackInfo {
253+
TargetCommand::BleUpdate(BleStackInfo {
265254
file: std::path::PathBuf::from("stack.bin"),
266255
address: HexAddress(0x123),
267256
version: None,

0 commit comments

Comments
 (0)