Skip to content

Commit

Permalink
add clap app
Browse files Browse the repository at this point in the history
  • Loading branch information
najeal committed May 23, 2024
1 parent bd394c3 commit ea76769
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rust-license.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
headers: |
// Copyright (c) 2024 najeal, All rights reserved.
// See the file LICENSE for licensing terms.
59 changes: 59 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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<String>
}

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);
}
}
},
_ => (),
}
}

0 comments on commit ea76769

Please sign in to comment.