licensebat_cli/
cli.rs

1use std::str::FromStr;
2use structopt::StructOpt;
3
4/// Struct representing the args of the CLI.
5#[derive(Debug, StructOpt, Clone)]
6#[structopt(
7    name = "๐Ÿฆ‡  Licensebat",
8    author("๐Ÿ’ป  Roberto Huertas <roberto.huertas@outlook.com>"),
9    long_about = "๐Ÿงฐ  Utility to help you check that your project's dependencies comply with your license policy.\n๐Ÿฆ€  Humbly written with Rust. ๐Ÿงก\n  
10    โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„
11    โ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–€โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–„โ–‘โ–„
12    โ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–„โ–ˆโ–‘โ–ˆโ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–ˆโ–ˆโ–‘โ–ˆโ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–€โ–€โ–‘โ–ˆโ–ˆโ–‘โ–ˆ
13    โ–ˆโ–ˆโ–‘โ–€โ–€โ–‘โ–ˆโ–„โ–„โ–„โ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–„โ–„โ–„โ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆ
14    โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€                                       
15"
16)]
17pub struct Cli {
18    /// Path to the file containing the dependencies of the project.
19    /// i.e. package-lock.json for npm projects, yarn.lock for yarn projects, etc.
20    #[structopt(short, long)]
21    pub dependency_file: String,
22    /// Path to the .licrc file
23    #[structopt(short, long, default_value = ".licrc")]
24    pub licrc_file: String,
25    /// Output format (json | markdown). Defaults to json.
26    #[structopt(short = "f", long, default_value = "json")]
27    pub output_format: OutputFormat,
28}
29
30/// Format of the CLIs output
31#[derive(Debug, Clone)]
32pub enum OutputFormat {
33    /// Json format
34    Json,
35    /// Markdown format
36    Markdown,
37}
38
39impl FromStr for OutputFormat {
40    type Err = &'static str;
41
42    fn from_str(s: &str) -> Result<Self, Self::Err> {
43        match s {
44            "markdown" | "md" => Ok(Self::Markdown),
45            _ => Ok(Self::Json),
46        }
47    }
48}