Skip to content

Commit 2072a86

Browse files
committed
cleanup-package-files: switch from structopt to clap
1 parent 345d914 commit 2072a86

File tree

3 files changed

+55
-122
lines changed

3 files changed

+55
-122
lines changed

cleanup-package-files/Cargo.lock

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

cleanup-package-files/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ edition = "2021"
88
eyre = "*"
99
expanduser = "*"
1010
# since 1.4.0 it uses thiserror instead of failure
11-
pwd = "1.4"
11+
pwd = "*"
1212
nix = { version = "*", features = ["fs", "user"] }
13-
14-
[dependencies.structopt]
15-
version = "*"
16-
default-features = false
17-
features = []
13+
clap = { version = "*", default-features = false, features = ["std", "derive", "help", "usage", "error-context"] }
1814

1915
[profile.release]
2016
lto = true

cleanup-package-files/src/main.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fs::File;
66

77
use expanduser::expanduser;
88
use eyre::{Result, ensure, eyre};
9-
use structopt::StructOpt;
9+
use clap::Parser;
1010
use nix::fcntl::Flock;
1111

1212
const LILAC_LOCK: &str = "~lilydjwg/.lilac/.lock";
@@ -35,29 +35,28 @@ fn git_ls_files() -> Result<Vec<OsString>> {
3535
)
3636
}
3737

38-
#[derive(StructOpt, Debug)]
39-
#[structopt(name = "basic")]
40-
struct Opt {
38+
#[derive(Parser, Debug)]
39+
struct Cli {
4140
/// remove files for real; or only print what will be removed
42-
#[structopt(long="real")]
41+
#[arg(long="real")]
4342
real: bool,
4443
pkgname: String,
4544
}
4645

4746
fn main() -> Result<()> {
48-
let opt = Opt::from_args();
47+
let cli = Cli::parse();
4948

5049
let pwd = pwd::Passwd::from_name(USER)
5150
.map_err(|e| eyre!("cannot get passwd entry for user {}: {:?}", USER, e))?
5251
.unwrap();
5352
nix::unistd::setuid(nix::unistd::Uid::from_raw(pwd.uid))?;
5453

5554
let _lock;
56-
if opt.real {
55+
if cli.real {
5756
_lock = flock(expanduser(LILAC_LOCK)?)?;
5857
}
5958
let mut path = expanduser(LILAC_REPO)?;
60-
path.push(&opt.pkgname);
59+
path.push(&cli.pkgname);
6160

6261
std::env::set_current_dir(&path)?;
6362
let tracked_files = git_ls_files()?;
@@ -68,7 +67,7 @@ fn main() -> Result<()> {
6867
if tracked_files.contains(&file_name) {
6968
continue;
7069
}
71-
if opt.real {
70+
if cli.real {
7271
println!("rm -rf {}", entry.path().display());
7372
Command::new("rm").arg("-rf").arg(&file_name).spawn()?;
7473
} else {

0 commit comments

Comments
 (0)