Skip to content

Commit

Permalink
Migrate from structopt to clap v3 (#1293)
Browse files Browse the repository at this point in the history
`clap` v3 added support for a `structopt`-like parser derive usage.
`structopt` is now in maintenance mode
(https://docs.rs/structopt/latest/structopt/#maintenance); it is
recommended to migrate to `clap`.

Structs to parse CLI arguments have been renamed to `Args` for
consistency.
  • Loading branch information
david-perez committed Apr 11, 2022
1 parent aaed505 commit 3c25664
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 234 deletions.
155 changes: 84 additions & 71 deletions tools/sdk-lints/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 tools/sdk-lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
[dependencies]
anyhow = "1"
cargo_toml = "0.10.1"
clap = { version = "3.1.7", features = ["derive"]}
toml = "0.5.8"
structopt = "0.3.25"
serde = { version = "1", features = ["derive"]}
lazy_static = "1.4.0"
34 changes: 17 additions & 17 deletions tools/sdk-lints/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use crate::lint_cargo_toml::{CrateAuthor, CrateLicense, DocsRs};
use crate::readmes::{ReadmesExist, ReadmesHaveFooters};
use crate::todos::TodosHaveContext;
use anyhow::{bail, Context, Result};
use clap::Parser;
use lazy_static::lazy_static;
use std::env::set_current_dir;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{fs, io};
use structopt::StructOpt;

mod anchor;
mod changelog;
Expand All @@ -34,40 +34,40 @@ fn load_repo_root() -> Result<PathBuf> {
Ok(PathBuf::from(String::from_utf8(output.stdout)?.trim()))
}

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
enum Args {
Check {
#[structopt(long)]
#[clap(long)]
all: bool,
#[structopt(long)]
#[clap(long)]
readme: bool,
#[structopt(long)]
#[clap(long)]
cargo_toml: bool,
#[structopt(long)]
#[clap(long)]
docsrs_metadata: bool,
#[structopt(long)]
#[clap(long)]
changelog: bool,
#[structopt(long)]
#[clap(long)]
license: bool,
#[structopt(long)]
#[clap(long)]
todos: bool,
},
Fix {
#[structopt(long)]
#[clap(long)]
readme: bool,
#[structopt(long)]
#[clap(long)]
docsrs_metadata: bool,
#[structopt(long)]
#[clap(long)]
all: bool,
#[structopt(long)]
#[clap(long)]
dry_run: Option<bool>,
},
UpdateChangelog {
#[structopt(long)]
#[clap(long)]
smithy_version: String,
#[structopt(long)]
#[clap(long)]
sdk_version: String,
#[structopt(long)]
#[clap(long)]
date: String,
},
}
Expand Down Expand Up @@ -112,7 +112,7 @@ fn ok<T>(errors: Vec<T>) -> anyhow::Result<()> {

fn main() -> Result<()> {
set_current_dir(repo_root())?;
let opt = Args::from_args();
let opt = Args::parse();
match opt {
Args::Check {
all,
Expand Down
Loading

0 comments on commit 3c25664

Please sign in to comment.