<commit_before>use clap::{App, Arg, ArgGroup, AppSettings, SubCommand, ArgMatches, Shell};
use common;
use rustup::{Cfg, Toolchain, command};
use rustup::settings::TelemetryMode;
use errors::*;
use rustup_dist::manifest::Component;
use rustup_dist::dist::{TargetTriple, PartialToolchainDesc, PartialTargetTriple};
use rustup_utils::utils;
use self_update;
use std::path::Path;
use std::process::Command;
use std::iter;
use term2;
use std::io::{self, Write};
use help::*;

pub fn main() -> Result<()> {
    try!(::self_update::cleanup_self_updater());

    let ref matches = cli().get_matches();
    let verbose = matches.is_present("verbose");
    let ref cfg = try!(common::set_globals(verbose));

    if try!(maybe_upgrade_data(cfg, matches)) {
        return Ok(())
    }

    try!(cfg.check_metadata_version());

    match matches.subcommand() {
        ("show", Some(_)) => try!(show(cfg)),
        ("install", Some(m)) => try!(update(cfg, m)),
        ("update", Some(m)) => try!(update(cfg, m)),
        ("uninstall", Some(m)) => try!(toolchain_remove(cfg, m)),
        ("default", Some(m)) => try!(default_(cfg, m)),
        ("toolchain", Some(c)) => {
            match c.subcommand() {
                ("install", Some(m)) => try!(update(cfg, m)),
                ("list", Some(_)) => try!(common::list_toolchains(cfg)),
                ("link", Some(m)) => try!(toolchain_link(cfg, m)),
                ("uninstall", Some(m)) => try!(toolchain_remove(cfg, m)),
                // Synonyms
                ("update", Some(m)) => try!(update(cfg, m)),
                ("add", Some(m)) => try!(update(cfg, m)),
                ("remove", Some(m)) => try!(toolchain_remove(cfg, m)),
                (_, _) => unreachable!(),
            }
        }
        ("target", Some(c)) => {
            match c.subcommand() {
                ("list", Some(m)) => try!(target_list(cfg, m)),
                ("add", Some(m)) => try!(target_add(cfg, m)),
                ("remove", Some(m)) => try!(target_remove(cfg, m)),
                // Synonyms
                ("install", Some(m)) => try!(target_add(cfg, m)),
                ("uninstall", Some(m)) => try!(target_remove(cfg, m)),
                (_, _) => unreachable!(),
            }
        }
        ("component", Some(c)) => {
            match c.subcommand() {
                ("list", Some(m)) => try!(component_list(cfg, m)),
                ("add", Some(m)) => try!(component_add(cfg, m)),
                ("remove", Some(m)) => try!(component_remove(cfg, m)),
                (_, _) => unreachable!(),
            }
        }
        ("override", Some(c)) => {
            match c.subcommand() {
                ("list", Some(_)) => try!(common::list_overrides(cfg)),
                ("set", Some(m)) => try!(override_add(cfg, m)),
                ("unset", Some(m)) => try!(override_remove(cfg, m)),
                // Synonyms
                ("add", Some(m)) => try!(override_add(cfg, m)),
                ("remove", Some(m)) => try!(override_remove(cfg, m)),
                (_ ,_) => unreachable!(),
            }
        }
        ("run", Some(m)) => try!(run(cfg, m)),
        ("which", Some(m)) => try!(which(cfg, m)),
        ("doc", Some(m)) => try!(doc(cfg, m)),
        ("man", Some(m)) => try!(man(cfg,m)),
        ("self", Some(c)) => {
            match c.subcommand() {
                ("update", Some(_)) => try!(self_update::update()),
                ("uninstall", Some(m)) => try!(self_uninstall(m)),
                (_ ,_) => unreachable!(),
            }
        }
        ("telemetry", Some(c)) => {
            match c.subcommand() {
                ("enable", Some(_)) => try!(set_telemetry(&cfg, TelemetryMode::On)),
                ("disable", Some(_)) => try!(set_telemetry(&cfg, TelemetryMode::Off)),
                ("analyze", Some(_)) => try!(analyze_telemetry(&cfg)),
                (_, _) => unreachable!(),
            }
        }
        ("set", Some(c)) => {
            match c.subcommand() {
                ("default-host", Some(m)) => try!(set_default_host_triple(&cfg, m)),
                (_, _) => unreachable!(),
            }
        }
        ("completions", Some(c)) => {
            if let Some(shell) = c.value_of("shell") {
                cli().gen_completions_to("rustup", shell.parse::<Shell>().unwrap(), &mut io::stdout());
            }
        }
        (_, _) => unreachable!(),
    }

    Ok(())
}

pub fn cli() -> App<'static, 'static> {
    App::new("rustup")
        .version(common::version())
        .about("The Rust toolchain installer")
        .after_help(RUSTUP_HELP)
        .setting(AppSettings::VersionlessSubcommands)
        .setting(AppSettings::DeriveDisplayOrder)
        .setting(AppSettings::SubcommandRequiredElseHelp)
        .arg(Arg::with_name("verbose")
            .help("Enable verbose output")
            .short("v")
            .long("verbose"))
        .subcommand(SubCommand::with_name("show")
            .about("Show the active and installed toolchains")
            .after_help(SHOW_HELP))
        .subcommand(SubCommand::with_name("install")
            .about("Update Rust toolchains")
            .after_help(INSTALL_HELP)
            .setting(AppSettings::Hidden) // synonym for 'toolchain install'
            .arg(Arg::with_name("toolchain")
                .required(true)
                .multiple(true)))
        .subcommand(SubCommand::with_name("uninstall")
            .about("Uninstall Rust toolchains")
            .setting(AppSettings::Hidden) // synonym for 'toolchain uninstall'
            .arg(Arg::with_name("toolchain")
                .required(true)
                .multiple(true)))
        .subcommand(SubCommand::with_name("update")
            .about("Update Rust toolchains")
            .after_help(UPDATE_HELP)
            .arg(Arg::with_name("toolchain")
                .required(false)
                .multiple(true))
            .arg(Arg::with_name("no-self-update")
                .help("Don't perform self update when running the `rustup` command")
                .long("no-self-update")
                .takes_value(false)
                .hidden(true)))
        .subcommand(SubCommand::with_name("default")
            .about("Set the default toolchain")
            .after_help(DEFAULT_HELP)
            .arg(Arg::with_name("toolchain")
                .required(true)))
        .subcommand(SubCommand::with_name("toolchain")
            .about("Modify or query the installed toolchains")
            .after_help(TOOLCHAIN_HELP)
            .setting(AppSettings::VersionlessSubcommands)
            .setting(AppSettings::DeriveDisplayOrder)
            .setting(AppSettings::SubcommandRequiredElseHelp)
            .subcommand(SubCommand::with_name("list")
                .about("List installed toolchains"))
            .subcommand(SubCommand::with_name("install")
                .about("Install or update a given toolchain")
                .arg(Arg::with_name("toolchain")
                     .required(true)<commit_msg>Clarify that rustup update updates rustup itself<commit_after>use clap::{App, Arg, ArgGroup, AppSettings, SubCommand, ArgMatches, Shell};
use common;
use rustup::{Cfg, Toolchain, command};
use rustup::settings::TelemetryMode;
use errors::*;
use rustup_dist::manifest::Component;
use rustup_dist::dist::{TargetTriple, PartialToolchainDesc, PartialTargetTriple};
use rustup_utils::utils;
use self_update;
use std::path::Path;
use std::process::Command;
use std::iter;
use term2;
use std::io::{self, Write};
use help::*;

pub fn main() -> Result<()> {
    try!(::self_update::cleanup_self_updater());

    let ref matches = cli().get_matches();
    let verbose = matches.is_present("verbose");
    let ref cfg = try!(common::set_globals(verbose));

    if try!(maybe_upgrade_data(cfg, matches)) {
        return Ok(())
    }

    try!(cfg.check_metadata_version());

    match matches.subcommand() {
        ("show", Some(_)) => try!(show(cfg)),
        ("install", Some(m)) => try!(update(cfg, m)),
        ("update", Some(m)) => try!(update(cfg, m)),
        ("uninstall", Some(m)) => try!(toolchain_remove(cfg, m)),
        ("default", Some(m)) => try!(default_(cfg, m)),
        ("toolchain", Some(c)) => {
            match c.subcommand() {
                ("install", Some(m)) => try!(update(cfg, m)),
                ("list", Some(_)) => try!(common::list_toolchains(cfg)),
                ("link", Some(m)) => try!(toolchain_link(cfg, m)),
                ("uninstall", Some(m)) => try!(toolchain_remove(cfg, m)),
                // Synonyms
                ("update", Some(m)) => try!(update(cfg, m)),
                ("add", Some(m)) => try!(update(cfg, m)),
                ("remove", Some(m)) => try!(toolchain_remove(cfg, m)),
                (_, _) => unreachable!(),
            }
        }
        ("target", Some(c)) => {
            match c.subcommand() {
                ("list", Some(m)) => try!(target_list(cfg, m)),
                ("add", Some(m)) => try!(target_add(cfg, m)),
                ("remove", Some(m)) => try!(target_remove(cfg, m)),
                // Synonyms
                ("install", Some(m)) => try!(target_add(cfg, m)),
                ("uninstall", Some(m)) => try!(target_remove(cfg, m)),
                (_, _) => unreachable!(),
            }
        }
        ("component", Some(c)) => {
            match c.subcommand() {
                ("list", Some(m)) => try!(component_list(cfg, m)),
                ("add", Some(m)) => try!(component_add(cfg, m)),
                ("remove", Some(m)) => try!(component_remove(cfg, m)),
                (_, _) => unreachable!(),
            }
        }
        ("override", Some(c)) => {
            match c.subcommand() {
                ("list", Some(_)) => try!(common::list_overrides(cfg)),
                ("set", Some(m)) => try!(override_add(cfg, m)),
                ("unset", Some(m)) => try!(override_remove(cfg, m)),
                // Synonyms
                ("add", Some(m)) => try!(override_add(cfg, m)),
                ("remove", Some(m)) => try!(override_remove(cfg, m)),
                (_ ,_) => unreachable!(),
            }
        }
        ("run", Some(m)) => try!(run(cfg, m)),
        ("which", Some(m)) => try!(which(cfg, m)),
        ("doc", Some(m)) => try!(doc(cfg, m)),
        ("man", Some(m)) => try!(man(cfg,m)),
        ("self", Some(c)) => {
            match c.subcommand() {
                ("update", Some(_)) => try!(self_update::update()),
                ("uninstall", Some(m)) => try!(self_uninstall(m)),
                (_ ,_) => unreachable!(),
            }
        }
        ("telemetry", Some(c)) => {
            match c.subcommand() {
                ("enable", Some(_)) => try!(set_telemetry(&cfg, TelemetryMode::On)),
                ("disable", Some(_)) => try!(set_telemetry(&cfg, TelemetryMode::Off)),
                ("analyze", Some(_)) => try!(analyze_telemetry(&cfg)),
                (_, _) => unreachable!(),
            }
        }
        ("set", Some(c)) => {
            match c.subcommand() {
                ("default-host", Some(m)) => try!(set_default_host_triple(&cfg, m)),
                (_, _) => unreachable!(),
            }
        }
        ("completions", Some(c)) => {
            if let Some(shell) = c.value_of("shell") {
                cli().gen_completions_to("rustup", shell.parse::<Shell>().unwrap(), &mut io::stdout());
            }
        }
        (_, _) => unreachable!(),
    }

    Ok(())
}

pub fn cli() -> App<'static, 'static> {
    App::new("rustup")
        .version(common::version())
        .about("The Rust toolchain installer")
        .after_help(RUSTUP_HELP)
        .setting(AppSettings::VersionlessSubcommands)
        .setting(AppSettings::DeriveDisplayOrder)
        .setting(AppSettings::SubcommandRequiredElseHelp)
        .arg(Arg::with_name("verbose")
            .help("Enable verbose output")
            .short("v")
            .long("verbose"))
        .subcommand(SubCommand::with_name("show")
            .about("Show the active and installed toolchains")
            .after_help(SHOW_HELP))
        .subcommand(SubCommand::with_name("install")
            .about("Update Rust toolchains")
            .after_help(INSTALL_HELP)
            .setting(AppSettings::Hidden) // synonym for 'toolchain install'
            .arg(Arg::with_name("toolchain")
                .required(true)
                .multiple(true)))
        .subcommand(SubCommand::with_name("uninstall")
            .about("Uninstall Rust toolchains")
            .setting(AppSettings::Hidden) // synonym for 'toolchain uninstall'
            .arg(Arg::with_name("toolchain")
                .required(true)
                .multiple(true)))
        .subcommand(SubCommand::with_name("update")
            .about("Update Rust toolchains and rustup")
            .after_help(UPDATE_HELP)
            .arg(Arg::with_name("toolchain")
                .required(false)
                .multiple(true))
            .arg(Arg::with_name("no-self-update")
                .help("Don't perform self update when running the `rustup` command")
                .long("no-self-update")
                .takes_value(false)
                .hidden(true)))
        .subcommand(SubCommand::with_name("default")
            .about("Set the default toolchain")
            .after_help(DEFAULT_HELP)
            .arg(Arg::with_name("toolchain")
                .required(true)))
        .subcommand(SubCommand::with_name("toolchain")
            .about("Modify or query the installed toolchains")
            .after_help(TOOLCHAIN_HELP)
            .setting(AppSettings::VersionlessSubcommands)
            .setting(AppSettings::DeriveDisplayOrder)
            .setting(AppSettings::SubcommandRequiredElseHelp)
            .subcommand(SubCommand::with_name("list")
                .about("List installed toolchains"))
            .subcommand(SubCommand::with_name("install")
                .about("Install or update a given toolchain")
                .arg(Arg::with_name("toolchain")
                     .required(true)
{'fraction_non_alphanumeric': 0.18144417647893318, 'fraction_numerical': 0.00014186409419775854, 'mean_word_length': 2.100725753243897, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 115, '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': '641235', 'n_tokens_mistral': 4212, 'n_tokens_neox': 4066, 'n_words': 717}