Skip to content

Commit bee73c6

Browse files
authored
cli: update to clap 4 (#108)
Specify next_display_order = None to keep the option list sorted in --help. Pretend to continue supporting clap 3 in Cargo.toml so cargo < 1.60 won't fail when building with the CLI disabled. Delete Cargo.lock in MSRV CI jobs for the same reason.
1 parent 8cb5b77 commit bee73c6

File tree

4 files changed

+133
-41
lines changed

4 files changed

+133
-41
lines changed

.github/workflows/rust.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ jobs:
2222
rust:
2323
- stable
2424
- 1.46.0 # lib MSRV
25-
- 1.57.0 # cli MSRV
25+
- 1.60.0 # cli MSRV
2626
include:
2727
- os: ubuntu-latest
2828
rust: stable
2929
lint: 1
3030
- rust: stable
3131
rust-args: --all-features
32-
- rust: 1.57.0
32+
- rust: 1.46.0
33+
no-lock: 1
34+
- rust: 1.60.0
3335
rust-args: --all-features
3436
runs-on: ${{ matrix.os }}
3537
steps:
@@ -44,6 +46,15 @@ jobs:
4446

4547
- uses: Swatinem/rust-cache@v1
4648

49+
# If we're testing with Rust < 1.60, cargo won't be able to find
50+
# the clap version specified in Cargo.lock, so remove the lockfile.
51+
# This is safe because applications that only use us as a library will
52+
# also ignore our Cargo.lock.
53+
# https://users.rust-lang.org/t/optional-dependencies-and-msrv/82151
54+
- name: Prune Cargo.lock
55+
if: matrix.no-lock
56+
run: rm Cargo.lock
57+
4758
- name: cargo test
4859
uses: actions-rs/cargo@v1
4960
with:

Cargo.lock

Lines changed: 104 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ pad = { version = "0.1", optional = true }
3333
unicode-width = { version = "0.1.8", optional = true }
3434
linefeed = { version = "0.6.0", optional = true }
3535
rand = { version = "0.8", optional = true }
36-
clap = { version = "3.1", optional = true, features = ["derive"] }
36+
# We don't actually support clap 3. But cargo < 1.60 ignores clap versions
37+
# >= 4, and our MSRV is lower than that when the CLI is disabled. Ensure
38+
# older cargo can find _some_ clap version so it won't fail.
39+
# https://users.rust-lang.org/t/optional-dependencies-and-msrv/82151
40+
clap = { version = ">= 3, < 5", optional = true, features = ["derive", "wrap_help"] }
3741
count-zeroes = { version = "0.2.0", optional = true }
3842

3943
[features]

src/cli/opt.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use clap::{ArgEnum, Parser};
1+
use clap::{Parser, ValueEnum};
22
use std::path::PathBuf;
33

4-
#[derive(ArgEnum, Clone, Debug)]
4+
#[derive(Clone, Debug, ValueEnum)]
55
pub enum Column {
66
Device,
77
Start,
@@ -15,36 +15,36 @@ pub enum Column {
1515
}
1616

1717
#[derive(Parser, Debug)]
18-
#[clap(version)]
18+
#[command(next_display_order = None, version)]
1919
pub struct Opt {
2020
/// display partitions and exit
21-
#[clap(short = 'l', long = "list")]
21+
#[arg(short = 'l', long = "list")]
2222
pub print: bool,
2323

2424
/// output columns
25-
#[clap(
25+
#[arg(
2626
short = 'o',
2727
long = "output",
28-
arg_enum,
28+
value_enum,
2929
default_value = "device,start,end,sectors,size,type,guid,attributes,name",
30-
use_value_delimiter = true
30+
value_delimiter = ','
3131
)]
3232
pub columns: Vec<Column>,
3333

3434
/// device to open
35-
#[clap(name = "DEVICE", parse(from_os_str))]
35+
#[arg(value_name = "DEVICE")]
3636
pub device: PathBuf,
3737

3838
/// initialize a new GPT on the disk
39-
#[clap(short = 'i', long = "init")]
39+
#[arg(short = 'i', long = "init")]
4040
pub init: bool,
4141

4242
/// sector size
43-
#[clap(short = 'b', long = "sector-size")]
43+
#[arg(short = 'b', long = "sector-size")]
4444
pub sector_size: Option<u64>,
4545

4646
/// partition alignment
47-
#[clap(short = 'a', long = "align")]
47+
#[arg(short = 'a', long = "align")]
4848
pub align: Option<u64>,
4949
}
5050

0 commit comments

Comments
 (0)