diff --git a/rust-license.yaml b/rust-license.yaml new file mode 100644 index 0000000..466c805 --- /dev/null +++ b/rust-license.yaml @@ -0,0 +1,3 @@ +headers: | + // Copyright (c) 2024 najeal, All rights reserved. + // See the file LICENSE for licensing terms. diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..42bb80a --- /dev/null +++ b/src/main.rs @@ -0,0 +1,59 @@ +mod config; +mod check; +mod licenser; +mod errors; +use clap::{Parser, Subcommand}; + +/// Simple program to greet a person +#[derive(Parser, Debug)] +#[command(name = "rust-license")] +#[command(version = "0.1")] +#[command(about= "program to manage rust-licenses", long_about = None)] +struct Args { + #[command(subcommand)] + cmd: RootSubCommand, +} + +#[derive(Subcommand, Debug)] +enum RootSubCommand{ + LicenseHeader(LicenseHeader), +} + +#[derive(Parser, Debug)] +struct LicenseHeader { + #[arg(long)] + config: String, + #[arg(short, long)] + apply: bool, + #[arg(short, long)] + remove: bool, + #[arg(short, long)] + check: bool, + files: Vec +} + +fn main() { + let args = Args::parse(); + match args.cmd { + RootSubCommand::LicenseHeader (cmd) => { + let cfg = config::load(&cmd.config).unwrap(); + if !(cmd.apply ^ cmd.remove ^ cmd.check ) { + panic!("apply - remove - check flags should be used independently") + } + let s = licenser::Licenser::new(cmd.files, cfg); + if cmd.apply { + let _ = s.apply_files_license().unwrap(); + } + if cmd.remove { + let _ = s.remove_files_license().unwrap(); + } + if cmd.check { + let no_license_list = s.check_files_license().unwrap(); + for elem in no_license_list.iter() { + println!("{}", elem); + } + } + }, + _ => (), + } +} \ No newline at end of file