Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Merge #357
Browse files Browse the repository at this point in the history
357: Update to `clap 4.0` r=Dajamante a=Urhengulas

This PR updates our cli parser `clap` from `2.34` to `4.0`.

The end-user experience should stay similar, but has a fresh UI, many internal improvements, and better help messages when a user gets the arguments wrong.

On the left you can see the new UI, and on the right the old.
![image](https://user-images.githubusercontent.com/37087391/194344377-e49958f1-412e-45f4-9199-8108d8356368.png)


Co-authored-by: Urhengulas <[email protected]>
  • Loading branch information
bors[bot] and Urhengulas authored Oct 6, 2022
2 parents f5dd134 + 8e6cff7 commit 69fd4bf
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 119 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

- [#357] Update to `clap 4.0`
- [#349] Add `PROBE_RUN_SPEED` env variable
- [#345] Update dev-dependency `serial_test`
- [#344] Replace `pub(crate)` with `pub`
- [#343] Mark `v0.3.4` as released in `CHANGELOG.md`
- [#353] add option to verify written flash
- [#353] Add option to verify written flash

[#357]: https://github.com/knurling-rs/probe-run/pull/357
[#349]: https://github.com/knurling-rs/probe-run/pull/349
[#345]: https://github.com/knurling-rs/probe-run/pull/345
[#344]: https://github.com/knurling-rs/probe-run/pull/344
Expand Down
122 changes: 57 additions & 65 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ addr2line = { version = "0.18", default-features = false, features = [
"cpp_demangle",
] }
anyhow = "1"
clap = { version = "4.0", features = ["derive", "env"] }
colored = "2"
defmt-decoder = { version = "=0.3.3", features = ["unstable"] }
gimli = { version = "0.26", default-features = false }
Expand All @@ -27,7 +28,6 @@ object = { version = "0.29", default-features = false }
probe-rs = "0.13"
probe-rs-rtt = "0.13"
signal-hook = "0.3"
structopt = "0.3"

[dev-dependencies]
dirs = "4"
Expand Down
108 changes: 56 additions & 52 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,102 +1,106 @@
use std::path::PathBuf;

use clap::{ArgAction, Parser};
use defmt_decoder::DEFMT_VERSION;
use git_version::git_version;
use log::Level;
use probe_rs::Probe;
use structopt::{clap::AppSettings, StructOpt};

use crate::probe;

/// Successfull termination of process.
const EXIT_SUCCESS: i32 = 0;

/// A Cargo runner for microcontrollers.
#[derive(StructOpt)]
#[structopt(name = "probe-run", setting = AppSettings::TrailingVarArg)]
#[derive(Parser)]
#[command()]
pub struct Opts {
/// List supported chips and exit.
#[structopt(long)]
list_chips: bool,
/// Disable or enable backtrace (auto in case of panic or stack overflow).
#[arg(long, default_value = "auto")]
pub backtrace: String,

/// Lists all the connected probes and exit.
#[structopt(long)]
list_probes: bool,
/// Configure the number of lines to print before a backtrace gets cut off.
#[arg(long, default_value = "50")]
pub backtrace_limit: u32,

/// The chip to program.
#[structopt(long, required_unless_one(&["list-chips", "list-probes", "version"]), env = "PROBE_RUN_CHIP")]
#[arg(long, required = true, conflicts_with_all = HELPER_CMDS, env = "PROBE_RUN_CHIP")]
chip: Option<String>,

/// Path to chip description file, in YAML format.
#[structopt(long)]
#[arg(long)]
pub chip_description_path: Option<PathBuf>,

/// The probe to use (eg. `VID:PID`, `VID:PID:Serial`, or just `Serial`).
#[structopt(long, env = "PROBE_RUN_PROBE")]
pub probe: Option<String>,
/// Connect to device when NRST is pressed.
#[arg(long)]
pub connect_under_reset: bool,

/// The probe clock frequency in kHz
#[structopt(long, env = "PROBE_RUN_SPEED")]
pub speed: Option<u32>,
/// Disable use of double buffering while downloading flash.
#[arg(long)]
pub disable_double_buffering: bool,

/// Path to an ELF firmware file.
#[structopt(name = "ELF", parse(from_os_str), required_unless_one(&["list-chips", "list-probes", "version"]))]
#[arg(required = true, conflicts_with_all = HELPER_CMDS)]
elf: Option<PathBuf>,

/// Output logs a structured json.
#[arg(long)]
pub json: bool,

/// List supported chips and exit.
#[arg(long)]
list_chips: bool,

/// Lists all the connected probes and exit.
#[arg(long)]
list_probes: bool,

/// Whether to measure the program's stack consumption.
#[arg(long)]
pub measure_stack: bool,

/// Skip writing the application binary to flash.
#[structopt(
#[arg(
long,
conflicts_with = "disable-double-buffering",
conflicts_with = "disable_double_buffering",
conflicts_with = "verify"
)]
pub no_flash: bool,

/// Connect to device when NRST is pressed.
#[structopt(long)]
pub connect_under_reset: bool,

/// Enable more verbose output.
#[structopt(short, long, parse(from_occurrences))]
pub verbose: u32,

/// Prints version information
#[structopt(short = "V", long)]
version: bool,

/// Disable or enable backtrace (auto in case of panic or stack overflow).
#[structopt(long, default_value = "auto")]
pub backtrace: String,

/// Configure the number of lines to print before a backtrace gets cut off
#[structopt(long, default_value = "50")]
pub backtrace_limit: u32,
/// The probe to use (eg. `VID:PID`, `VID:PID:Serial`, or just `Serial`).
#[arg(long, env = "PROBE_RUN_PROBE")]
pub probe: Option<String>,

/// Whether to shorten paths (e.g. to crates.io dependencies) in backtraces and defmt logs
#[structopt(long)]
#[arg(long)]
pub shorten_paths: bool,

/// Whether to measure the program's stack consumption.
#[structopt(long)]
pub measure_stack: bool,

#[structopt(long)]
pub json: bool,
/// The probe clock frequency in kHz
#[arg(long, env = "PROBE_RUN_SPEED")]
pub speed: Option<u32>,

/// Disable use of double buffering while downloading flash
#[structopt(long = "disable-double-buffering")]
pub disable_double_buffering: bool,
/// Enable more verbose output.
#[arg(short, long, action = ArgAction::Count)]
pub verbose: u8,

/// Verifies the written program.
#[structopt(long)]
#[arg(long)]
pub verify: bool,

/// Prints version information
#[arg(short = 'V', long)]
version: bool,

/// Arguments passed after the ELF file path are discarded
#[structopt(name = "REST")]
#[arg(allow_hyphen_values = true, hide = true, trailing_var_arg = true)]
_rest: Vec<String>,
}

/// Helper commands, which will not execute probe-run normally.
const HELPER_CMDS: [&str; 3] = ["list_chips", "list_probes", "version"];

pub fn handle_arguments() -> anyhow::Result<i32> {
let opts: Opts = Opts::from_args();
let opts = Opts::parse();
let verbose = opts.verbose;

defmt_decoder::log::init_logger(verbose >= 1, opts.json, move |metadata| {
Expand Down

0 comments on commit 69fd4bf

Please sign in to comment.