<commit_before>mod settings;
#[cfg(test)]
mod tests;

pub use self::settings::AppSettings;

// Std
use std::collections::HashMap;
use std::env;
use std::ffi::OsString;
use std::fmt;
use std::io::{self, BufRead, BufWriter, Write};
use std::path::Path;
use std::process;

// Third Party
#[cfg(feature = "yaml")]
use yaml_rust::Yaml;

// Internal
use crate::build::{app::settings::AppFlags, Arg, ArgGroup, ArgSettings};
use crate::mkeymap::MKeyMap;
use crate::output::fmt::ColorWhen;
use crate::output::{Help, Usage};
use crate::parse::errors::Result as ClapResult;
use crate::parse::{ArgMatcher, ArgMatches, Input, Parser};
use crate::util::{Key, HELP_HASH, VERSION_HASH};
use crate::INTERNAL_ERROR_MSG;

type Id = u64;

// FIXME (@CreepySkeleton): some of this variants are never constructed
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[allow(unused)]
pub(crate) enum Propagation {
    To(Id),
    Full,
    NextLevel,
    None,
}

/// Used to create a representation of a command line program and all possible command line
/// arguments. Application settings are set using the "builder pattern" with the
/// [`App::get_matches`] family of methods being the terminal methods that starts the
/// runtime-parsing process. These methods then return information about the user supplied
/// arguments (or lack there of).
///
/// **NOTE:** There aren't any mandatory "options" that one must set. The "options" may
/// also appear in any order (so long as one of the [`App::get_matches`] methods is the last method
/// called).
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
/// let m = App::new("My Program")
///     .author("Me, <EMAIL>")
///     .version("1.0.2")
///     .about("Explains in brief what the program does")
///     .arg(
///         Arg::with_name("in_file").index(1)
///     )
///     .after_help("Longer explanation to appear after the options when \
///                  displaying the help information from --help or -h")
///     .get_matches();
///
/// // Your program logic starts here...
/// ```
/// [`App::get_matches`]: ./struct.App.html#method.get_matches
#[derive(Default, Debug, Clone)]
pub struct App<'b> {
    pub(crate) id: Id,
    #[doc(hidden)]
    pub name: String,
    #[doc(hidden)]
    pub bin_name: Option<String>,
    pub(crate) author: Option<&'b str>,
    pub(crate) version: Option<&'b str>,
    pub(crate) long_version: Option<&'b str>,
    #[doc(hidden)]
    pub about: Option<&'b str>,
    pub(crate) long_about: Option<&'b str>,
    pub(crate) more_help: Option<&'b str>,
    pub(crate) pre_help: Option<&'b str>,
    #[doc(hidden)]
    pub aliases: Option<Vec<(&'b str, bool)>>, // (name, visible)
    pub(crate) usage_str: Option<&'b str>,
    pub(crate) usage: Option<String>,
    pub(crate) help_str: Option<&'b str>,
    pub(crate) disp_ord: usize,
    pub(crate) term_w: Option<usize>,
    pub(crate) max_w: Option<usize>,
    pub(crate) template: Option<&'b str>,
    pub(crate) settings: AppFlags,
    pub(crate) g_settings: AppFlags,
    #[doc(hidden)]
    pub args: MKeyMap<'b>,
    #[doc(hidden)]
    pub subcommands: Vec<App<'b>>,
    pub(crate) replacers: HashMap<&'b str, &'b [&'b str]>,
    pub(crate) groups: Vec<ArgGroup<'b>>,
    pub(crate) help_headings: Vec<Option<&'b str>>,
}

impl<'b> App<'b> {
    /// Creates a new instance of an application requiring a name. The name may be, but doesn't
    /// have to be, same as the binary. The name will be displayed to the user when they request to
    /// print version or help and usage information.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # use clap::{App, Arg};
    /// let prog = App::new("My Program")
    /// # ;
    /// ```
    pub fn new<S: Into<String>>(n: S) -> Self {
        let name = n.into();
        let id = name.key();
        App {
            id,
            name,
            ..Default::default()
        }
    }

    /// Get the name of the app
    pub fn get_name(&self) -> &str {
        &self.name
    }

    /// Get the name of the binary
    pub fn get_bin_name(&self) -> Option<&str> {
        self.bin_name.as_deref()
    }

    /// Sets a string of author(s) that will be displayed to the user when they
    /// request the help information with `--help` or `-h`.<commit_msg>set the default disp_ord of App to 999. Required for display_order and DeriveDisplay to work properly<commit_after>mod settings;
#[cfg(test)]
mod tests;

pub use self::settings::AppSettings;

// Std
use std::collections::HashMap;
use std::env;
use std::ffi::OsString;
use std::fmt;
use std::io::{self, BufRead, BufWriter, Write};
use std::path::Path;
use std::process;

// Third Party
#[cfg(feature = "yaml")]
use yaml_rust::Yaml;

// Internal
use crate::build::{app::settings::AppFlags, Arg, ArgGroup, ArgSettings};
use crate::mkeymap::MKeyMap;
use crate::output::fmt::ColorWhen;
use crate::output::{Help, Usage};
use crate::parse::errors::Result as ClapResult;
use crate::parse::{ArgMatcher, ArgMatches, Input, Parser};
use crate::util::{Key, HELP_HASH, VERSION_HASH};
use crate::INTERNAL_ERROR_MSG;

type Id = u64;

// FIXME (@CreepySkeleton): some of this variants are never constructed
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[allow(unused)]
pub(crate) enum Propagation {
    To(Id),
    Full,
    NextLevel,
    None,
}

/// Used to create a representation of a command line program and all possible command line
/// arguments. Application settings are set using the "builder pattern" with the
/// [`App::get_matches`] family of methods being the terminal methods that starts the
/// runtime-parsing process. These methods then return information about the user supplied
/// arguments (or lack there of).
///
/// **NOTE:** There aren't any mandatory "options" that one must set. The "options" may
/// also appear in any order (so long as one of the [`App::get_matches`] methods is the last method
/// called).
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg};
/// let m = App::new("My Program")
///     .author("Me, <EMAIL>")
///     .version("1.0.2")
///     .about("Explains in brief what the program does")
///     .arg(
///         Arg::with_name("in_file").index(1)
///     )
///     .after_help("Longer explanation to appear after the options when \
///                  displaying the help information from --help or -h")
///     .get_matches();
///
/// // Your program logic starts here...
/// ```
/// [`App::get_matches`]: ./struct.App.html#method.get_matches
#[derive(Default, Debug, Clone)]
pub struct App<'b> {
    pub(crate) id: Id,
    #[doc(hidden)]
    pub name: String,
    #[doc(hidden)]
    pub bin_name: Option<String>,
    pub(crate) author: Option<&'b str>,
    pub(crate) version: Option<&'b str>,
    pub(crate) long_version: Option<&'b str>,
    #[doc(hidden)]
    pub about: Option<&'b str>,
    pub(crate) long_about: Option<&'b str>,
    pub(crate) more_help: Option<&'b str>,
    pub(crate) pre_help: Option<&'b str>,
    #[doc(hidden)]
    pub aliases: Option<Vec<(&'b str, bool)>>, // (name, visible)
    pub(crate) usage_str: Option<&'b str>,
    pub(crate) usage: Option<String>,
    pub(crate) help_str: Option<&'b str>,
    pub(crate) disp_ord: usize,
    pub(crate) term_w: Option<usize>,
    pub(crate) max_w: Option<usize>,
    pub(crate) template: Option<&'b str>,
    pub(crate) settings: AppFlags,
    pub(crate) g_settings: AppFlags,
    #[doc(hidden)]
    pub args: MKeyMap<'b>,
    #[doc(hidden)]
    pub subcommands: Vec<App<'b>>,
    pub(crate) replacers: HashMap<&'b str, &'b [&'b str]>,
    pub(crate) groups: Vec<ArgGroup<'b>>,
    pub(crate) help_headings: Vec<Option<&'b str>>,
}

impl<'b> App<'b> {
    /// Creates a new instance of an application requiring a name. The name may be, but doesn't
    /// have to be, same as the binary. The name will be displayed to the user when they request to
    /// print version or help and usage information.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// # use clap::{App, Arg};
    /// let prog = App::new("My Program")
    /// # ;
    /// ```
    pub fn new<S: Into<String>>(n: S) -> Self {
        let name = n.into();
        let id = name.key();
        App {
            id,
            name,
            disp_ord: 999,
            ..Default::default()
        }
    }

    /// Get the name of the app
    pub fn get_name(&self) -> &str {
        &self.name
    }

    /// Get the name of the binary
    pub fn get_bin_name(&self) -> Option<&str> {
        self.bin_name.as_deref()
    }

    /// Sets a string of author(s) that will be displayed to the user when they
    /// request the help information with `--help` or `-h`.
{'fraction_non_alphanumeric': 0.17020536025060912, 'fraction_numerical': 0.002088409328228333, 'mean_word_length': 2.9705204974666053, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1835817', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2892, 'n_words': 882}