From 7f33e4a0481e88e6339c49b06422ee2524b5d002 Mon Sep 17 00:00:00 2001 From: Wynd Date: Thu, 22 Aug 2024 23:52:24 +0300 Subject: [PATCH] Actually made it work like a cargo extension --- Cargo.toml | 13 ++++++++++++- src/main.rs | 11 +++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 39a9bcb..744fdce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,19 @@ name = "cargo-semver" version = "0.1.0" edition = "2021" +keywords = ["cargo", "semver"] +categories = [ + "development-tools", + "development-tools::cargo-plugins", + "development-tools::build-utils", + "command-line-utilities", +] + +[[bin]] +name = "cargo-semver" +path = "src/main.rs" [dependencies] toml_edit = { version = "0.22.20" } semver = { version = "1.0.23" } -clap = { version = "4.5.16", features = ["derive"] } +clap = { version = "4.5.16", features = ["derive", "cargo"] } diff --git a/src/main.rs b/src/main.rs index de99f3f..7f158dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,16 @@ use clap::{command, Parser}; use semver::Version; use toml_edit::{value, DocumentMut}; +#[derive(Parser)] +#[command(name = "cargo")] +#[command(bin_name = "cargo")] +enum CargoCli { + Semver(SemverArgs), +} + #[derive(Clone, Debug, Parser, PartialEq, Eq)] #[command(version, about, long_about = None)] -pub struct CliArgs { +pub struct SemverArgs { #[arg(long("bump-patch"), default_value_t = false)] pub bump_patch: bool, @@ -18,7 +25,7 @@ pub struct CliArgs { } fn main() { - let args = CliArgs::parse(); + let CargoCli::Semver(args) = CargoCli::parse(); if !args.bump_major && !args.bump_minor && !args.bump_patch { panic!("Specify which version to bump by using --bump-patch --bump-minor or --bump-major");