Skip to content

Commit

Permalink
chore!: rename tool to pipfile-util
Browse files Browse the repository at this point in the history
This name is a bit more universal for upcoming features
  • Loading branch information
markus-k committed Oct 28, 2022
1 parent 0a2bb74 commit 125531d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 31 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -9,7 +9,7 @@ description = "Command line utility to create a diff of Pipfile.lock"
keywords = ["python", "pipenv", "git"]

authors = ["Markus Kasten <github@markuskasten.eu>"]
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

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# `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

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:
Expand Down Expand Up @@ -64,26 +64,26 @@ 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 .
```

## License

`pipfile-diff` is licensed under the Apache-2.0 license.
`pipfile-util` is licensed under the Apache-2.0 license.
53 changes: 36 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::Parser;
use clap::{Parser, Subcommand};
use std::path::PathBuf;

mod diff;
Expand All @@ -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<PathBuf>,

#[arg(
short = 'r',
long,
help = "Git reference to compare to. Defaults to HEAD"
)]
git_ref: Option<String>,
},
}

#[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<PathBuf>,

#[arg(
short = 'r',
long,
help = "Git reference to compare to. Defaults to HEAD"
)]
git_ref: Option<String>,
#[command(subcommand)]
subcommand: SubCommand,
}

fn main() -> anyhow::Result<()> {
let args = Args::parse();

fn subcommand_diff(pipfile_lock: Option<PathBuf>, git_ref: Option<String>) -> 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
Expand Down Expand Up @@ -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(())
}

0 comments on commit 125531d

Please sign in to comment.