Skip to content

Commit bbfe023

Browse files
authored
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
1 parent c639461 commit bbfe023

File tree

5 files changed

+100
-29
lines changed

5 files changed

+100
-29
lines changed

Cargo.lock

Lines changed: 64 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "MIT"
77
repository = "https://github.com/azu/license-generator"
88
version = "1.2.0"
99
authors = ["azu <[email protected]>"]
10-
edition = "2018"
10+
edition = "2021"
1111
include = [
1212
"files/**/*",
1313
"src/**/*",
@@ -16,5 +16,5 @@ include = [
1616
"LICENSE"
1717
]
1818
[dependencies]
19-
structopt = "0.2.14"
19+
structopt = "0.3.26"
2020
chrono = "0.4"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Install with [Cargo](https://crates.io/):
2727
- Unlicense
2828

2929
Options:
30+
-l, --list lists the available licenses
3031
--author input author name. Default: `GitName <GitEmail>`
3132
--project input project name that is required by some license
3233
--year input license year

src/license.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@ pub trait License {
22
fn notice(&self, year: u32, name: &str, project: &str) -> String;
33
}
44

5+
pub const LICENSES: [&str; 16] = [
6+
"AGPL",
7+
"Apache",
8+
"BSD",
9+
"CC0",
10+
"CC-BY",
11+
"CC-BY-NC",
12+
"CC-BY-NC-SA",
13+
"CC-BY-SA",
14+
"EUPL-1.2",
15+
"GPL-2",
16+
"GPL-3",
17+
"ISC",
18+
"LGPL-3",
19+
"MIT",
20+
"MPL-2",
21+
"Unlicense"
22+
];
23+
524
// agpl-3.0.txt
625
pub struct AGPL {}
726

src/main.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use std::process::{self, Command};
1111

1212
#[derive(StructOpt, Debug)]
1313
struct Opt {
14-
#[structopt(name = "INPUT", required = true)]
14+
#[structopt(short, long, help = "Lists valid license types")]
15+
list: bool,
16+
#[structopt(name = "INPUT", required_unless("list"))]
1517
inputs: Vec<String>,
1618
#[structopt(long = "author")]
1719
author: Option<String>,
@@ -25,6 +27,17 @@ struct Opt {
2527

2628
fn main() -> Result<(), Box<dyn std::error::Error>> {
2729
let opt = Opt::from_args();
30+
31+
if opt.list {
32+
println!("Supported Licenses are:");
33+
use license_generator::license::LICENSES;
34+
for l in LICENSES {
35+
print!("{}, ", l);
36+
}
37+
println!();
38+
return Ok(());
39+
}
40+
2841
let year = if let Some(year) = opt.year {
2942
year
3043
} else {

0 commit comments

Comments
 (0)