### Licensebat CLI Usage Example Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/index.html?search=u32+-%3E+bool Example of the Licensebat CLI usage with options for dependency file and output format. ```bash licensebat [OPTIONS] --dependency-file ``` -------------------------------- ### Example Search Queries Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/index.html?search= Illustrative examples of search queries that can be performed, demonstrating different patterns and types. ```text std::vec ``` ```text u32 -> bool ``` ```text Option, (T -> U) -> Option ``` -------------------------------- ### Basic Search Example: std::vec Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/lib.rs.html?search= Demonstrates a simple search query for the `std::vec` type. This is a common starting point for exploring Rust's standard library. ```text std::vec ``` -------------------------------- ### Run Licensebat CLI with Dependency File Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/lib.rs.html Example of how to run the licensebat CLI with a specific dependency file and set the RUST_LOG environment variable for logging. ```bash #!/bin/bash RUST_LOG=licensebat=info cargo run --dependency-file ./Cargo.lock ``` -------------------------------- ### Licensebat .licrc Configuration File Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/index.html Example TOML configuration file for Licensebat, specifying accepted/denied licenses, ignored dependencies, and behavior settings. ```toml [licenses] # This indicates which are the only licenses that Licensebat will accept. # The rest will be flagged as not allowed. accepted = ["MIT", "MSC", "BSD"] # This will indicate which licenses are not accepted. # The rest will be accepted, except for the unknown licenses or dependencies without licenses. # unaccepted = ["LGPL"] # Note that only one of the previous options can be enabled at once. # If both of them are informed, only accepted will be considered. [dependencies] # This will allow users to flag some dependencies so that Licensebat will not check for their license. ignored=["ignored_dep1", "ignored_dep2"] # If set to true, Licensebat will ignore the dev dependencies. ignore_dev_dependencies = true # If set to true, Licensebat will ignore the optional dependencies. ignore_optional_dependencies = true [behavior] # False by default (always exit code == 0), if true, it will exit with code 1 in case some invalid dependency is found. do_not_block_pr = false # This will define the size of the buffer used to retrieve the dependencies. # It's set to 100 by default. # If you have a lot of dependencies, you might want to increase this value, but be careful, if the size is too big, the API might return an error. retriever_buffer_size: 100, ``` -------------------------------- ### Type Conversion Search Example: u32 -> bool Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/lib.rs.html?search= Shows how to search for type conversions, specifically from `u32` to `bool`. This is useful for understanding type casting and conversion rules. ```text u32 -> bool ``` -------------------------------- ### Licensebat CLI Build Configuration Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Configuration for the licensebat CLI, including HTML logo and favicon URLs, and module declarations. This setup is typical for Rust projects aiming for detailed documentation. ```rust #![doc(html_logo_url = "https://licensebat.com/images/not_used/logo_red_ferris.png")] #![doc(html_favicon_url = "https://licensebat.com/images/not_used/favicons_red/favicon.ico")] #![allow(clippy::module_name_repetitions)] #![warn(missing_docs)] ``` -------------------------------- ### Generic Type Conversion Search Example: Option, (T -> U) -> Option Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/lib.rs.html?search= Illustrates searching for generic type conversions involving `Option`. This pattern is common when dealing with optional values and transformations. ```text Option, (T -> U) -> Option ``` -------------------------------- ### Main `run` function for licensebat CLI Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/check.rs.html This is the primary entry point for the licensebat CLI. It initializes necessary components like the SPDX store and HTTP client, reads configuration, collects dependency information, and validates them against the .licrc configuration. Errors can occur during file reading or dependency manifest parsing. ```rust use crate::Cli; use futures::StreamExt; use licensebat_core::{licrc::LicRc, FileCollector, RetrievedDependency}; use std::sync::Arc; const LICENSE_CACHE: &[u8] = std::include_bytes!("../license-cache.bin.zstd"); #[derive(Debug, thiserror::Error)] enum CheckError { #[error("Error reading dependency file: {0}")] DependencyFile(#[from] std::io::Error), } /// Result of the dependency validation. pub struct RunResult { /// The [`LicRc`] file. pub licrc: LicRc, /// The validated dependencies. pub dependencies: Vec, } /// Checks the dependencies of a project. /// /// This is the main entry point of the CLI. /// /// # Errors /// /// Errors can be caused by many causes, including: /// - Reading a dependency manifest file (package-lock.json, yarn.lock, etc.) /// - Reading the .licrc file pub async fn run(cli: Cli) -> anyhow::Result { tracing::info!( dependency_file = %cli.dependency_file, "Licensebat running! Using {}" cli.dependency_file ); // 0. spdx store & http client let store = Arc::new(askalono::Store::from_cache(LICENSE_CACHE).ok()); let client = reqwest::Client::builder() .no_proxy() // .danger_accept_invalid_certs(true) // .pool_idle_timeout(None) .build() .expect("Failed to build HTTP client"); // 1 .get information from .licrc file tracing::debug!("Reading .licrc file"); let licrc = LicRc::from_relative_path(cli.licrc_file)?; // 2. get content of the dependency file tracing::debug!("Getting dependency file content"); let dep_file_content = get_dep_file_content(&cli.dependency_file).await?; // 3. create collectors tracing::debug!("Building collectors"); let npm_retriever = licensebat_js::retriever::Npm::new(client.clone()); let npm_collector = licensebat_js::collector::Npm::new(npm_retriever.clone()); let yarn_collector = licensebat_js::collector::Yarn::new(npm_retriever); let rust_collector = licensebat_rust::collector::Rust::with_docs_rs_retriever(client.clone(), store.clone()); let dart_collector = licensebat_dart::collector::Dart::with_hosted_retriever(client, store); let file_collectors: Vec> = vec![ Box::new(npm_collector), Box::new(yarn_collector), Box::new(rust_collector), Box::new(dart_collector), ]; // 4. get dependency stream let mut stream = file_collectors .iter() .find(|c| cli.dependency_file.contains(&c.get_dependency_filename())) .and_then(|c| c.get_dependencies(&dep_file_content, &licrc).ok()) .expect( format!("No collector found for dependency file {}", cli.dependency_file) .as_str(), ) .buffer_unordered(licrc.behavior.retriever_buffer_size.unwrap_or(100)); // 5. validate the dependencies according to the .licrc config tracing::debug!("Validating dependencies"); let mut validated_deps = vec![]; while let Some(mut dependency) = stream.next().await { // do the validation here licrc.validate(&mut dependency); validated_deps.push(dependency); } tracing::info!("Done!"); Ok(RunResult { licrc, dependencies: validated_deps, }) } ``` -------------------------------- ### Main CLI Entry Point for Licensebat Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/check.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E The `run` function orchestrates the dependency checking process. It initializes necessary components like the SPDX store and HTTP client, reads the `.licrc` configuration, fetches dependency file content, sets up various collectors for different package managers, and streams dependencies for validation. ```rust use crate::Cli; use futures::StreamExt; use licensebat_core::{licrc::LicRc, FileCollector, RetrievedDependency}; use std::sync::Arc; const LICENSE_CACHE: &[u8] = std::include_bytes!("../license-cache.bin.zstd"); #[derive(Debug, thiserror::Error)] enum CheckError { #[error("Error reading dependency file: {0}")] DependencyFile(#[from] std::io::Error), } /// Result of the dependency validation. pub struct RunResult { /// The [`LicRc`] file. pub licrc: LicRc, /// The validated dependencies. pub dependencies: Vec, } /// Checks the dependencies of a project. /// /// This is the main entry point of the CLI. /// /// # Errors /// /// Errors can be caused by many causes, including: /// - Reading a dependency manifest file (package-lock.json, yarn.lock, etc.) /// - Reading the .licrc file pub async fn run(cli: Cli) -> anyhow::Result { tracing::info!( dependency_file = %cli.dependency_file, "Licensebat running! Using {}" , cli.dependency_file ); // 0. spdx store & http client let store = Arc::new(askalono::Store::from_cache(LICENSE_CACHE).ok()); let client = reqwest::Client::builder() .no_proxy() // .danger_accept_invalid_certs(true) // .pool_idle_timeout(None) .build() .expect("Failed to build HTTP client"); // 1 .get information from .licrc file tracing::debug!("Reading .licrc file"); let licrc = LicRc::from_relative_path(cli.licrc_file)?; // 2. get content of the dependency file tracing::debug!("Getting dependency file content"); let dep_file_content = get_dep_file_content(&cli.dependency_file).await?; // 3. create collectors tracing::debug!("Building collectors"); let npm_retriever = licensebat_js::retriever::Npm::new(client.clone()); let npm_collector = licensebat_js::collector::Npm::new(npm_retriever.clone()); let yarn_collector = licensebat_js::collector::Yarn::new(npm_retriever); let rust_collector = licensebat_rust::collector::Rust::with_docs_rs_retriever(client.clone(), store.clone()); let dart_collector = licensebat_dart::collector::Dart::with_hosted_retriever(client, store); let file_collectors: Vec> = vec![ Box::new(npm_collector), Box::new(yarn_collector), Box::new(rust_collector), Box::new(dart_collector), ]; // 4. get dependency stream let mut stream = file_collectors .iter() .find(|c| cli.dependency_file.contains(&c.get_dependency_filename())) .and_then(|c| c.get_dependencies(&dep_file_content, &licrc).ok()) .expect( format!("No collector found for dependency file {}", cli.dependency_file) .as_str(), ) .buffer_unordered(licrc.behavior.retriever_buffer_size.unwrap_or(100)); // 5. validate the dependencies according to the .licrc config tracing::debug!("Validating dependencies"); let mut validated_deps = vec![]; while let Some(mut dependency) = stream.next().await { // do the validation here licrc.validate(&mut dependency); validated_deps.push(dependency); } tracing::info!("Done!"); Ok(RunResult { licrc, dependencies: validated_deps, }) } ``` -------------------------------- ### Licensebat CLI Usage Help Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/lib.rs.html?search=u32+-%3E+bool Display help information for the licensebat CLI, including available options and flags. ```txt USAGE: licensebat [OPTIONS] --dependency-file FLAGS: -h, --help Prints help information -V, --version Prints version information OPTIONS: -d, --dependency-file Path to the file containing the dependencies of the project. i.e. package-lock.json for npm projects, yarn.lock for yarn projects, etc -l, --licrc-file Path to the .licrc file [default: .licrc] -f, --output-format Output format (json | markdown). Defaults to json. ``` -------------------------------- ### Licensebat CLI Usage Help Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/index.html Display help information for the Licensebat CLI, including available options and flags. ```bash licensebat --help ``` -------------------------------- ### Run Function Signature Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/fn.run.html?search= This is the main entry point of the CLI. It checks the dependencies of a project. ```rust pub async fn run(cli: Cli) -> Result ``` -------------------------------- ### Run Licensebat CLI Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/index.html Execute the Licensebat CLI to check dependencies. Requires a dependency file and internet access. ```bash licensebat --dependency-file ./Cargo.lock ``` -------------------------------- ### Main Dependency Checking Function Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/check.rs.html?search= The `run` function is the primary entry point for the CLI. It orchestrates the process of reading configuration, collecting dependency information, and validating licenses. ```rust use crate::Cli; use futures::StreamExt; use licensebat_core::{licrc::LicRc, FileCollector, RetrievedDependency}; use std::sync::Arc; const LICENSE_CACHE: &[u8] = std::include_bytes!("../license-cache.bin.zstd"); #[derive(Debug, thiserror::Error)] enum CheckError { #[error("Error reading dependency file: {0}")] DependencyFile(#[from] std::io::Error), } /// Result of the dependency validation. pub struct RunResult { /// The [`LicRc`] file. pub licrc: LicRc, /// The validated dependencies. pub dependencies: Vec, } /// Checks the dependencies of a project. /// /// This is the main entry point of the CLI. /// /// # Errors /// /// Errors can be caused by many causes, including: /// - Reading a dependency manifest file (package-lock.json, yarn.lock, etc.) /// - Reading the .licrc file pub async fn run(cli: Cli) -> anyhow::Result { tracing::info!( dependency_file = %cli.dependency_file, "Licensebat running! Using {}" cli.dependency_file ); // 0. spdx store & http client let store = Arc::new(askalono::Store::from_cache(LICENSE_CACHE).ok()); let client = reqwest::Client::builder() .no_proxy() // .danger_accept_invalid_certs(true) // .pool_idle_timeout(None) .build() .expect("Failed to build HTTP client"); // 1 .get information from .licrc file tracing::debug!("Reading .licrc file"); let licrc = LicRc::from_relative_path(cli.licrc_file)?; // 2. get content of the dependency file tracing::debug!("Getting dependency file content"); let dep_file_content = get_dep_file_content(&cli.dependency_file).await?; // 3. create collectors tracing::debug!("Building collectors"); let npm_retriever = licensebat_js::retriever::Npm::new(client.clone()); let npm_collector = licensebat_js::collector::Npm::new(npm_retriever.clone()); let yarn_collector = licensebat_js::collector::Yarn::new(npm_retriever); let rust_collector = licensebat_rust::collector::Rust::with_docs_rs_retriever(client.clone(), store.clone()); let dart_collector = licensebat_dart::collector::Dart::with_hosted_retriever(client, store); let file_collectors: Vec> = vec![ Box::new(npm_collector), Box::new(yarn_collector), Box::new(rust_collector), Box::new(dart_collector), ]; // 4. get dependency stream let mut stream = file_collectors .iter() .find(|c| cli.dependency_file.contains(&c.get_dependency_filename())) .and_then(|c| c.get_dependencies(&dep_file_content, &licrc).ok()) .expect( format!( "No collector found for dependency file {}", cli.dependency_file ) .as_str(), ) .buffer_unordered(licrc.behavior.retriever_buffer_size.unwrap_or(100)); // 5. validate the dependencies according to the .licrc config tracing::debug!("Validating dependencies"); let mut validated_deps = vec![]; while let Some(mut dependency) = stream.next().await { // do the validation here licrc.validate(&mut dependency); validated_deps.push(dependency); } tracing::info!("Done!"); Ok(RunResult { licrc, dependencies: validated_deps, }) } ``` -------------------------------- ### Licensebat CLI Options Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/index.html Overview of Licensebat CLI command-line options for specifying dependency files, configuration files, and output formats. ```text USAGE: licensebat [OPTIONS] --dependency-file FLAGS: -h, --help Prints help information -V, --version Prints version information OPTIONS: -d, --dependency-file Path to the file containing the dependencies of the project. i.e. package-lock.json for npm projects, yarn.lock for yarn projects, etc -l, --licrc-file Path to the .licrc file [default: .licrc] -f, --output-format Output format (json | markdown). Defaults to json. ``` -------------------------------- ### Enable Licensebat Logging Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/lib.rs.html Configure logging for Licensebat by setting the RUST_LOG environment variable. ```bash # Licensebat uses tracing. You can get logs while running the CLI by setting the RUST_LOG environment variable. ``` -------------------------------- ### Enable Licensebat Logs Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/index.html Run Licensebat with the RUST_LOG environment variable set to 'licensebat=info' to enable detailed logs during dependency checking. ```bash RUST_LOG=licensebat=info cargo run --dependency-file ./Cargo.lock ``` -------------------------------- ### run Function Signature Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/fn.run.html The run function is the main entry point of the CLI. It takes a Cli struct as input and returns a Result containing a RunResult, indicating success or failure. Errors can occur during the reading of dependency manifest files or the .licrc configuration file. ```APIDOC ## run ### Description Checks the dependencies of a project. This is the main entry point of the CLI. ### Signature ```rust pub async fn run(cli: Cli) -> Result ``` ### Errors Errors can be caused by many causes, including: * Reading a dependency manifest file (package-lock.json, yarn.lock, etc.) * Reading the .licrc file ``` -------------------------------- ### Licensebat CLI Arguments Structure Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/cli.rs.html?search=std%3A%3Avec Defines the main structure for command-line arguments, including dependency file path, license configuration file path, and output format. ```rust use std::str::FromStr; use structopt::StructOpt; /// Struct representing the args of the CLI. #[derive(Debug, StructOpt, Clone)] #[structopt( name = "๐Ÿฆ‡ Licensebat", author("๐Ÿ’ป Roberto Huertas "), long_about = "๐Ÿงฐ Utility to help you check that your project's dependencies comply with your license policy.\n๐Ÿฆ€ Humbly written with Rust. ๐Ÿงก\n โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–€โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–„โ–‘โ–„ โ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–„โ–ˆโ–‘โ–ˆโ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–ˆโ–ˆโ–‘โ–ˆโ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–€โ–€โ–‘โ–ˆโ–ˆโ–‘โ–ˆ โ–ˆโ–ˆโ–‘โ–€โ–€โ–‘โ–ˆโ–„โ–„โ–„โ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–„โ–„โ–„โ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ " )] pub struct Cli { /// Path to the file containing the dependencies of the project. /// i.e. package-lock.json for npm projects, yarn.lock for yarn projects, etc. #[structopt(short, long)] pub dependency_file: String, /// Path to the .licrc file #[structopt(short, long, default_value = ".licrc")] pub licrc_file: String, /// Output format (json | markdown). Defaults to json. #[structopt(short = "f", long, default_value = "json")] pub output_format: OutputFormat, } ``` -------------------------------- ### Enabling Logs with RUST_LOG Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/lib.rs.html?search= Set the RUST_LOG environment variable to view logs generated by Licensebat, which uses the tracing crate. ```bash RUST_LOG=info cargo run ``` -------------------------------- ### Licensebat CLI Arguments Structure Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/cli.rs.html Defines the structure for command-line arguments using the StructOpt derive macro. Includes fields for dependency file, license configuration file, and output format. ```rust use std::str::FromStr; use structopt::StructOpt; /// Struct representing the args of the CLI. #[derive(Debug, StructOpt, Clone)] #[structopt( name = "๐Ÿฆ‡ Licensebat", author("๐Ÿ’ป Roberto Huertas "), long_about = "๐Ÿงฐ Utility to help you check that your project's dependencies comply with your license policy.\n๐Ÿฆ€ Humbly written with Rust. ๐Ÿงก โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–€โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–„โ–‘โ–„ โ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–„โ–ˆโ–‘โ–ˆโ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–ˆโ–ˆโ–‘โ–ˆโ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–€โ–€โ–‘โ–ˆโ–ˆโ–‘โ–ˆ โ–ˆโ–ˆโ–‘โ–€โ–€โ–‘โ–ˆโ–„โ–„โ–„โ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–„โ–„โ–„โ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ ") ] pub struct Cli { /// Path to the file containing the dependencies of the project. /// i.e. package-lock.json for npm projects, yarn.lock for yarn projects, etc. #[structopt(short, long)] pub dependency_file: String, /// Path to the .licrc file #[structopt(short, long, default_value = ".licrc")] pub licrc_file: String, /// Output format (json | markdown). Defaults to json. #[structopt(short = "f", long, default_value = "json")] pub output_format: OutputFormat, } ``` -------------------------------- ### CLI Argument Structure Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/cli.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Defines the main structure for command-line arguments using `structopt`. It includes fields for the dependency file path, the license configuration file path, and the desired output format. ```rust use std::str::FromStr; use structopt::StructOpt; /// Struct representing the args of the CLI. #[derive(Debug, StructOpt, Clone)] #[structopt( name = "๐Ÿฆ‡ Licensebat", author("๐Ÿ’ป Roberto Huertas "), long_about = "๐Ÿงฐ Utility to help you check that your project's dependencies comply with your license policy.\n๐Ÿฆ€ Humbly written with Rust. ๐Ÿงก โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–€โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–„โ–‘โ–„ โ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–„โ–ˆโ–‘โ–ˆโ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–ˆโ–ˆโ–‘โ–ˆโ–„โ–„โ–€โ–ˆโ–‘โ–„โ–„โ–ˆโ–‘โ–„โ–„โ–€โ–ˆโ–‘โ–€โ–€โ–‘โ–ˆโ–ˆโ–‘โ–ˆ โ–ˆโ–ˆโ–‘โ–€โ–€โ–‘โ–ˆโ–„โ–„โ–„โ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–„โ–„โ–ˆโ–„โ–„โ–„โ–„โ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆโ–ˆโ–„โ–ˆ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ " )] pub struct Cli { /// Path to the file containing the dependencies of the project. /// i.e. package-lock.json for npm projects, yarn.lock for yarn projects, etc. #[structopt(short, long)] pub dependency_file: String, /// Path to the .licrc file #[structopt(short, long, default_value = ".licrc")] pub licrc_file: String, /// Output format (json | markdown). Defaults to json. #[structopt(short = "f", long, default_value = "json")] pub output_format: OutputFormat, } ``` -------------------------------- ### Helper function to read dependency file content Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/check.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E The `get_dep_file_content` function asynchronously reads the content of a specified dependency file from the current directory. It handles potential I/O errors during file reading and maps them to the `CheckError::DependencyFile` variant. ```rust async fn get_dep_file_content(dependency_file: &str) -> Result { async { let dep_file_path = std::env::current_dir()?.join(dependency_file); let dep_file_content = tokio::fs::read_to_string(dep_file_path).await?; Ok(dep_file_content) } .await .map_err(CheckError::DependencyFile) } ``` -------------------------------- ### Helper Function to Read Dependency File Content Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/check.rs.html?search= This asynchronous helper function reads the content of a specified dependency file from the current directory. ```rust async fn get_dep_file_content(dependency_file: &str) -> Result { async { let dep_file_path = std::env::current_dir()?.join(dependency_file); let dep_file_content = tokio::fs::read_to_string(dep_file_path).await?; Ok(dep_file_content) } .await .map_err(CheckError::DependencyFile) } ``` -------------------------------- ### Any Trait Implementation Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides runtime type information for a type. This is often used in generic programming and dynamic dispatch scenarios. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Licensebat CLI Development Warning Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/index.html?search=u32+-%3E+bool A warning indicating that licensebat-cli is under development and should be used with caution. ```text **Warning**: licensebat-cli is still in development so you may use it at your own risk. ``` -------------------------------- ### RunResult::try_from Generic Signature Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/lib.rs.html?search=u32+-%3E+bool Illustrates the generic signature of the `try_from` method in `RunResult`. It shows how `U` (which must match `u32`) is converted to `Result`, where `T` must match `bool`. This is relevant when dealing with type conversions within the CLI's result handling. ```rust pub trait TryFrom: Sized { type Error: Debug; fn try_from(value: U) -> Result; } impl TryFrom for bool { type Error = (); fn try_from(value: u32) -> Result { match value { 0 => Ok(false), 1 => Ok(true), _ => Err(()), } } } ``` -------------------------------- ### RunResult::try_from Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=u32+-%3E+bool Demonstrates the generic signature of the try_from method on RunResult, where U is u32 and T is bool. This indicates a conversion attempt from a u32 type to a bool type. ```APIDOC ## Method: try_from ### Description Attempts to convert a value of type `U` into `T` for the `RunResult` struct. ### Signature ```rust impl TryFrom for T where U: Into, ``` ### Type Parameters - `T`: The target type for the conversion. - `U`: The source type for the conversion. ### Specific Usage - `U` matches `u32` - `T` matches `bool` This specific instantiation implies a conversion from `u32` to `bool`. ``` -------------------------------- ### Licensebat Output Format Enum and Implementation Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/cli.rs.html Defines the OutputFormat enum for JSON or Markdown output and implements the FromStr trait for parsing string inputs into the enum variants. ```rust /// Format of the CLIs output #[derive(Debug, Clone)] pub enum OutputFormat { /// Json format Json, /// Markdown format Markdown, } impl FromStr for OutputFormat { type Err = &'static str; fn from_str(s: &str) -> Result { match s { "markdown" | "md" => Ok(Self::Markdown), _ => Ok(Self::Json), } } } ``` -------------------------------- ### TryInto Trait Implementation Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides a way to attempt conversion into another type, returning a Result. This is useful for fallible conversions where the target type might not be constructible from the source. ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### TryFrom Trait Implementation Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides a fallible conversion from one type to another, returning a Result. This is the counterpart to `TryInto` and is used when a conversion might fail. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Into Trait Implementation Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Enables conversion into another type by calling the `From` trait implementation. This is a common way to handle type conversions when the conversion is guaranteed to succeed. ```rust fn into(self) -> U ``` -------------------------------- ### Pointable Trait Implementations Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides low-level pointer manipulation capabilities, including initialization, dereferencing, and dropping. Use with caution as it involves unsafe operations. ```rust unsafe fn init(init: ::Init) -> usize ``` ```rust unsafe fn deref<'a>(ptr: usize) -> &'a T ``` ```rust unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T ``` ```rust unsafe fn drop(ptr: usize) ``` -------------------------------- ### WithSubscriber Trait Implementations Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Allows attaching a subscriber to a type, returning a wrapper that dispatches events. This is useful for integrating with tracing or logging systems. ```rust fn with_subscriber(self, subscriber: S) -> WithDispatch where S: Into, ``` ```rust fn with_current_subscriber(self) -> WithDispatch ``` -------------------------------- ### Licensebat CLI Module Declarations Source: https://docs.rs/licensebat-cli/latest/src/licensebat_cli/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Declares and re-exports modules for the licensebat CLI. This includes the 'check' module for running checks and the 'cli' module for command-line interface functionalities. ```rust mod check; mod cli; pub use check::{run, RunResult}; #[doc(hidden)] pub use cli::{Cli, OutputFormat}; ``` -------------------------------- ### RunResult Struct Definition Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search= Defines the structure for RunResult, which holds the LicRc file and a vector of RetrievedDependency. ```rust pub struct RunResult { pub licrc: LicRc, pub dependencies: Vec, } ``` -------------------------------- ### Instrument Trait Implementations Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Enables instrumenting a type with a Span for tracing purposes. This helps in understanding the execution flow and performance of your code. ```rust fn instrument(self, span: Span) -> Instrumented ``` ```rust fn in_current_span(self) -> Instrumented ``` -------------------------------- ### From Trait Implementation Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Enables infallible conversion from one type to another. This is a common and straightforward way to create new values. ```rust fn from(t: T) -> T ``` -------------------------------- ### PolicyExt Trait Implementations Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Extends types with policy combinator methods like `and` and `or`. These are used to create complex policies by combining simpler ones. ```rust fn and(self, other: P) -> And where T: Policy, P: Policy, ``` ```rust fn or(self, other: P) -> Or where T: Policy, P: Policy, ``` -------------------------------- ### BorrowMut Trait Implementation Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Allows mutable borrowing of a value. This is fundamental for modifying data in place. ```rust fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### Borrow Trait Implementation Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Enables immutable borrowing of a value. This is used when you need to access data without modifying it. ```rust fn borrow(&self) -> &T ``` -------------------------------- ### IntoEither Trait Implementation Source: https://docs.rs/licensebat-cli/latest/licensebat_cli/struct.RunResult.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Converts the current type into either the left or right variant of an `Either` enum. This is useful for branching logic based on a condition. ```rust fn into_either(self, into_left: bool) -> Either ``` ```rust fn into_either_with(self, into_left: F) -> Either where F: FnOnce(&Self) -> bool, ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.