Skip to content

Commit

Permalink
feat: Add command-line option to list the supported licenses (#30)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Hoverth authored Sep 6, 2024
1 parent c639461 commit bbfe023
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 29 deletions.
90 changes: 64 additions & 26 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
repository = "https://github.com/azu/license-generator"
version = "1.2.0"
authors = ["azu <[email protected]>"]
edition = "2018"
edition = "2021"
include = [
"files/**/*",
"src/**/*",
Expand All @@ -16,5 +16,5 @@ include = [
"LICENSE"
]
[dependencies]
structopt = "0.2.14"
structopt = "0.3.26"
chrono = "0.4"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Install with [Cargo](https://crates.io/):
- Unlicense

Options:
-l, --list lists the available licenses
--author input author name. Default: `GitName <GitEmail>`
--project input project name that is required by some license
--year input license year
Expand Down
19 changes: 19 additions & 0 deletions src/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[structopt(long = "author")]
author: Option<String>,
Expand All @@ -25,6 +27,17 @@ struct Opt {

fn main() -> Result<(), Box<dyn std::error::Error>> {
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 {
Expand Down

0 comments on commit bbfe023

Please sign in to comment.