From bbfe023ce80fbb6de96e8e28bd5e58c076ba288f Mon Sep 17 00:00:00 2001 From: Thomas Dickson Date: Fri, 6 Sep 2024 01:09:38 +0000 Subject: [PATCH] feat: Add command-line option to list the supported licenses (#30) * feat: added gplv2 and eupl (english) * fix: added gpl2 to lib.rs * feat: added list option to binary * fix: formatting issue * doc: added list argument to readme --- Cargo.lock | 90 +++++++++++++++++++++++++++++++++++--------------- Cargo.toml | 4 +-- README.md | 1 + src/license.rs | 19 +++++++++++ src/main.rs | 15 ++++++++- 5 files changed, 100 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1b6d0c..6972a8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "ansi_term" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ "winapi", ] @@ -41,9 +41,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.32.0" +version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", @@ -63,6 +63,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.46" @@ -92,20 +98,44 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" -version = "0.4.24" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "0.6.10" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -127,27 +157,29 @@ dependencies = [ [[package]] name = "strsim" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.2.14" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad348dc73012fcf78c71f06f9d942232cdd4c859d4b6975e27836c3efc0c3" +checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" dependencies = [ "clap", + "lazy_static", "structopt-derive", ] [[package]] name = "structopt-derive" -version = "0.2.14" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef98172b1a00b0bec738508d3726540edcbd186d50dfd326f2b1febbb3559f04" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ "heck", + "proc-macro-error", "proc-macro2", "quote", "syn", @@ -155,13 +187,13 @@ dependencies = [ [[package]] name = "syn" -version = "0.15.24" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "734ecc29cd36e8123850d9bf21dfd62ef8300aaa8f879aabaa899721808be37c" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -177,9 +209,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" dependencies = [ "unicode-width", ] @@ -195,6 +227,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + [[package]] name = "unicode-segmentation" version = "1.2.1" @@ -207,18 +245,18 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" - [[package]] name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "winapi" version = "0.3.6" diff --git a/Cargo.toml b/Cargo.toml index 6109bfb..b853abb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT" repository = "https://github.com/azu/license-generator" version = "1.2.0" authors = ["azu "] -edition = "2018" +edition = "2021" include = [ "files/**/*", "src/**/*", @@ -16,5 +16,5 @@ include = [ "LICENSE" ] [dependencies] -structopt = "0.2.14" +structopt = "0.3.26" chrono = "0.4" diff --git a/README.md b/README.md index 7746c45..c228bec 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Install with [Cargo](https://crates.io/): - Unlicense Options: + -l, --list lists the available licenses --author input author name. Default: `GitName ` --project input project name that is required by some license --year input license year diff --git a/src/license.rs b/src/license.rs index 44a7bb6..fb0a527 100644 --- a/src/license.rs +++ b/src/license.rs @@ -2,6 +2,25 @@ pub trait License { fn notice(&self, year: u32, name: &str, project: &str) -> String; } +pub const LICENSES: [&str; 16] = [ + "AGPL", + "Apache", + "BSD", + "CC0", + "CC-BY", + "CC-BY-NC", + "CC-BY-NC-SA", + "CC-BY-SA", + "EUPL-1.2", + "GPL-2", + "GPL-3", + "ISC", + "LGPL-3", + "MIT", + "MPL-2", + "Unlicense" +]; + // agpl-3.0.txt pub struct AGPL {} diff --git a/src/main.rs b/src/main.rs index 0a36032..487cd66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,9 @@ use std::process::{self, Command}; #[derive(StructOpt, Debug)] struct Opt { - #[structopt(name = "INPUT", required = true)] + #[structopt(short, long, help = "Lists valid license types")] + list: bool, + #[structopt(name = "INPUT", required_unless("list"))] inputs: Vec, #[structopt(long = "author")] author: Option, @@ -25,6 +27,17 @@ struct Opt { fn main() -> Result<(), Box> { let opt = Opt::from_args(); + + if opt.list { + println!("Supported Licenses are:"); + use license_generator::license::LICENSES; + for l in LICENSES { + print!("{}, ", l); + } + println!(); + return Ok(()); + } + let year = if let Some(year) = opt.year { year } else {