From 125531d84e28e9935ecd2f02323286ea7d268238 Mon Sep 17 00:00:00 2001 From: Markus Kasten Date: Fri, 28 Oct 2022 09:48:27 +0200 Subject: [PATCH] chore!: rename tool to `pipfile-util` This name is a bit more universal for upcoming features --- Cargo.lock | 8 ++++---- Cargo.toml | 6 +++--- README.md | 14 +++++++------- src/main.rs | 53 ++++++++++++++++++++++++++++++++++++----------------- 4 files changed, 50 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8fc8b1f..b7a8804 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,9 +229,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.3.0" +version = "6.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" +checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9" [[package]] name = "percent-encoding" @@ -240,8 +240,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] -name = "pipfile-diff" -version = "0.1.0" +name = "pipfile-util" +version = "0.1.1" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 9e302e0..82ef419 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "pipfile-diff" -version = "0.1.0" +name = "pipfile-util" +version = "0.1.1" edition = "2021" license = "Apache-2.0" @@ -9,7 +9,7 @@ description = "Command line utility to create a diff of Pipfile.lock" keywords = ["python", "pipenv", "git"] authors = ["Markus Kasten "] -repository = "https://github.com/markus-k/pipfile-diff" +repository = "https://github.com/markus-k/pipfile-util" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index a263b49..d2a483b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# `pipfile-diff` +# `pipfile-util` A simple tool to compare changes in `Pipfile.lock`-files. By default, it compares your `Pipfile.lock` to the latest version committed to git. ## Usage @@ -6,7 +6,7 @@ A simple tool to compare changes in `Pipfile.lock`-files. By default, it compare To compare a freshly locked `Pipfile.lock` to the latest commited one, run ``` -$ pipfile-diff path/to/Pipfile.lock +$ pipfile-util diff path/to/Pipfile.lock Default: Changed: @@ -64,21 +64,21 @@ Deleted: toml: 0.10.2 ``` -The output from `pipfile-diff` can also be easily used to create commit messages: +The output from `pipfile-util diff` can also be easily used to create commit messages: ``` # lock your Pipfile to install updates pipenv lock git add Pipfile.lock -# create a commit, with the output from pipfile-diff as a template -git commit -t <(pipfile-diff) +# create a commit, with the output from pipfile-util as a template +git commit -t <(pipfile-util diff) ``` ## Installation ### From source -To install `pipfile-diff` from source, clone the repository and run +To install `pipfile-util` from source, clone the repository and run ``` cargo install --path . @@ -86,4 +86,4 @@ cargo install --path . ## License -`pipfile-diff` is licensed under the Apache-2.0 license. +`pipfile-util` is licensed under the Apache-2.0 license. diff --git a/src/main.rs b/src/main.rs index f214178..f1cf9e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use clap::Parser; +use clap::{Parser, Subcommand}; use std::path::PathBuf; mod diff; @@ -7,33 +7,39 @@ mod pipfile_lock; use crate::diff::{print_diff, Diff}; use crate::pipfile_lock::PipfileLock; +#[derive(Debug, Subcommand)] +enum SubCommand { + Diff { + #[arg( + help = "Path to Pipfile.lock. If omitted, assumes Pipfile.lock in the current directory" + )] + pipfile_lock: Option, + + #[arg( + short = 'r', + long, + help = "Git reference to compare to. Defaults to HEAD" + )] + git_ref: Option, + }, +} + #[derive(Debug, Parser)] #[command(author, version, about)] struct Args { - #[arg( - help = "Path to Pipfile.lock. If omitted, assumes Pipfile.lock in the current directory" - )] - pipfile_lock: Option, - - #[arg( - short = 'r', - long, - help = "Git reference to compare to. Defaults to HEAD" - )] - git_ref: Option, + #[command(subcommand)] + subcommand: SubCommand, } -fn main() -> anyhow::Result<()> { - let args = Args::parse(); - +fn subcommand_diff(pipfile_lock: Option, git_ref: Option) -> anyhow::Result<()> { let pipfile_path = - std::fs::canonicalize(args.pipfile_lock.unwrap_or_else(|| "Pipfile.lock".into()))?; + std::fs::canonicalize(pipfile_lock.unwrap_or_else(|| "Pipfile.lock".into()))?; let file = std::fs::File::open(&pipfile_path)?; let lockfile = PipfileLock::from_reader(file)?; - let git_ref = args.git_ref.unwrap_or_else(|| "HEAD".to_owned()); + let git_ref = git_ref.unwrap_or_else(|| "HEAD".to_owned()); let repo = git2::Repository::discover(&pipfile_path.parent().unwrap())?; let path_in_repo: PathBuf = pipfile_path @@ -62,3 +68,16 @@ fn main() -> anyhow::Result<()> { Ok(()) } + +fn main() -> anyhow::Result<()> { + let args = Args::parse(); + + match args.subcommand { + SubCommand::Diff { + pipfile_lock, + git_ref, + } => subcommand_diff(pipfile_lock, git_ref)?, + }; + + Ok(()) +}