Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to clap@4.0.x #251

Merged
merged 4 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 61 additions & 25 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions cargo-espflash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ pkg-fmt = "zip"

[dependencies]
cargo_metadata = "0.15.0"
cargo_toml = "0.11.6"
clap = { version = "3.2.22", features = ["derive", "env"] }
env_logger = "0.9.0"
cargo_toml = "0.12.2"
clap = { version = "4.0.8", features = ["derive"] }
env_logger = "0.9.1"
espflash = { version = "=2.0.0-dev", path = "../espflash" }
log = "0.4.17"
miette = { version = "5.3.0", features = ["fancy"] }
serde = { version = "1.0.144", features = ["derive"] }
serde = { version = "1.0.145", features = ["derive"] }
strum = "0.24.1"
thiserror = "1.0.35"
thiserror = "1.0.37"
toml = "0.5.9"
7 changes: 5 additions & 2 deletions cargo-espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@ pub struct TomlError {
#[derive(Debug)]
pub enum MaybeTomlError {
Toml(toml::de::Error),
Other(std::io::Error),
Io(std::io::Error),
Other(&'static str),
}

impl From<cargo_toml::Error> for MaybeTomlError {
fn from(e: cargo_toml::Error) -> Self {
match e {
cargo_toml::Error::Parse(e) => MaybeTomlError::Toml(e),
cargo_toml::Error::Io(e) => MaybeTomlError::Other(e),
cargo_toml::Error::Io(e) => MaybeTomlError::Io(e),
cargo_toml::Error::Other(e) => MaybeTomlError::Other(e),
_ => todo!(), // `cargo_toml::Error` is marked as non-exhaustive
}
}
}
Expand Down
46 changes: 23 additions & 23 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use cargo_metadata::Message;
use clap::{Args, Parser, Subcommand};
use espflash::{
cli::{
board_info, config::Config, connect, flash_elf_image, monitor::monitor, partition_table,
save_elf_as_image, serial_monitor, ConnectArgs, FlashArgs as BaseFlashArgs,
FlashConfigArgs, PartitionTableArgs, SaveImageArgs as BaseSaveImageArgs,
self, board_info, clap_enum_variants, config::Config, connect, flash_elf_image,
monitor::monitor, partition_table, save_elf_as_image, serial_monitor, ConnectArgs,
FlashConfigArgs, PartitionTableArgs,
},
image_format::{ImageFormatId, ImageFormatType},
logging::initialize_logger,
Expand All @@ -33,7 +33,7 @@ mod error;
mod package_metadata;

#[derive(Debug, Parser)]
#[clap(bin_name = "cargo", propagate_version = true, version)]
#[clap(version, bin_name = "cargo", propagate_version = true)]
struct Cli {
#[clap(subcommand)]
subcommand: CargoSubcommand,
Expand Down Expand Up @@ -63,37 +63,34 @@ enum Commands {
#[derive(Debug, Args)]
struct BuildArgs {
/// Binary to build and flash
#[clap(long)]
#[arg(long)]
pub bin: Option<String>,
/// Example to build and flash
#[clap(long)]
#[arg(long)]
pub example: Option<String>,
/// Comma delimited list of build features
#[clap(long, use_value_delimiter = true)]
#[arg(long, use_value_delimiter = true)]
pub features: Option<Vec<String>>,
/// Image format to flash
#[clap(long, possible_values = ImageFormatType::VARIANTS)]
pub format: Option<String>,
/// Require Cargo.lock and cache are up to date
#[clap(long)]
#[arg(long)]
pub frozen: bool,
/// Require Cargo.lock is up to date
#[clap(long)]
#[arg(long)]
pub locked: bool,
/// Specify a (binary) package within a workspace to be built
#[clap(long)]
#[arg(long)]
pub package: Option<String>,
/// Build the application using the release profile
#[clap(long)]
#[arg(long)]
pub release: bool,
/// Target to build for
#[clap(long)]
#[arg(long)]
pub target: Option<String>,
/// Directory for all generated artifacts
#[clap(long)]
#[arg(long)]
pub target_dir: Option<String>,
/// Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
#[clap(short = 'Z')]
#[arg(short = 'Z')]
pub unstable: Option<Vec<String>>,

#[clap(flatten)]
Expand All @@ -108,20 +105,24 @@ struct FlashArgs {
#[clap(flatten)]
connect_args: ConnectArgs,
#[clap(flatten)]
flash_args: BaseFlashArgs,
flash_args: cli::FlashArgs,
}

#[derive(Debug, Args)]
struct SaveImageArgs {
/// Image format to flash
#[arg(long, value_parser = clap_enum_variants!(ImageFormatType))]
pub format: Option<String>,

#[clap(flatten)]
build_args: BuildArgs,
#[clap(flatten)]
save_image_args: BaseSaveImageArgs,
save_image_args: cli::SaveImageArgs,
}

fn main() -> Result<()> {
miette::set_panic_hook();
initialize_logger(LevelFilter::Debug);
initialize_logger(LevelFilter::Info);

// Attempt to parse any provided comand-line arguments, or print the help
// message and terminate if the invocation is not correct.
Expand Down Expand Up @@ -199,7 +200,7 @@ fn flash(
.or(build_ctx.partition_table_path.as_deref());

let image_format = args
.build_args
.flash_args
.format
.as_deref()
.map(ImageFormatId::from_str)
Expand All @@ -225,7 +226,7 @@ fn flash(
flasher.into_interface(),
Some(&elf_data),
pid,
args.connect_args.monitor_baud.unwrap_or(115_200),
args.flash_args.monitor_baud.unwrap_or(115_200),
)
.into_diagnostic()?;
}
Expand Down Expand Up @@ -419,7 +420,6 @@ fn save_image(
.map(|p| p.to_path_buf());

let image_format = args
.build_args
.format
.as_deref()
.map(ImageFormatId::from_str)
Expand Down
Loading