<commit_before>use std::env;
use std::path::Path;

use structopt::StructOpt;

use nmk::home::NmkHome;
use nmk::platform::is_mac;

mod backup;
mod build;
mod cmdline;
mod dotfiles;
mod entrypoint;
mod logging;
mod os_release;
mod settings;
mod updater;
mod vendor;

async fn main_task(opt: cmdline::Opt, _settings: settings::Settings) -> nmk::Result<()> {
    // Installation should be done in order
    let nmk_home = NmkHome::find_for_install().expect("Unable to locate NMK_HOME");
    assert!(!nmk_home.is_git(), "NMK_HOME is managed by git. Abort.");
    if opt.backup {
        backup::backup_files(&nmk_home)?;
    }
    dotfiles::install_or_update(&opt, &nmk_home).await?;
    if !is_mac() {
        let entrypoint_updated = entrypoint::install_or_update(&opt, &nmk_home).await?;
        updater::self_setup(&nmk_home, is_nmkup_init(), entrypoint_updated).await?;
        if opt.vendor {
            vendor::install(&opt, &nmk_home).await?;
        }
    }
    Ok(())
}

fn main() -> nmk::Result<()> {
    let opt = cmdline::Opt::from_args();
    let settings = settings::Settings::new(&opt);
    logging::setup(opt.verbosity);
    let mut rt = tokio::runtime::Builder::new()
        .basic_scheduler()
        .enable_all()
        .build()?;
    rt.block_on(main_task(opt, settings))
}

fn is_nmkup_init() -> bool {
    current_exec_stem().as_str().starts_with("nmkup-init")
}

fn current_exec_stem() -> String {
    env::args()
        .next()
        .map(std::path::PathBuf::from)
        .as_deref()
        .and_then(Path::file_stem)
        .and_then(std::ffi::OsStr::to_str)
        .map(String::from)
        .expect("Unable to parse argv[0] as String")
}<commit_msg>nmk: check init doesn't need file stem<commit_after>use std::path::Path;

use structopt::StructOpt;

use nmk::home::NmkHome;
use nmk::platform::is_mac;

mod backup;
mod build;
mod cmdline;
mod dotfiles;
mod entrypoint;
mod logging;
mod os_release;
mod settings;
mod updater;
mod vendor;

async fn main_task(opt: cmdline::Opt, _settings: settings::Settings) -> nmk::Result<()> {
    // Installation should be done in order
    let nmk_home = NmkHome::find_for_install().expect("Unable to locate NMK_HOME");
    assert!(!nmk_home.is_git(), "NMK_HOME is managed by git. Abort.");
    if opt.backup {
        backup::backup_files(&nmk_home)?;
    }
    dotfiles::install_or_update(&opt, &nmk_home).await?;
    if !is_mac() {
        let entrypoint_updated = entrypoint::install_or_update(&opt, &nmk_home).await?;
        updater::self_setup(&nmk_home, is_nmkup_init(), entrypoint_updated).await?;
        if opt.vendor {
            vendor::install(&opt, &nmk_home).await?;
        }
    }
    Ok(())
}

fn main() -> nmk::Result<()> {
    let opt = cmdline::Opt::from_args();
    let settings = settings::Settings::new(&opt);
    logging::setup(opt.verbosity);
    let mut rt = tokio::runtime::Builder::new()
        .basic_scheduler()
        .enable_all()
        .build()?;
    rt.block_on(main_task(opt, settings))
}

fn is_nmkup_init() -> bool {
    current_exec_name().starts_with("nmkup-init")
}

fn current_exec_name() -> String {
    std::env::current_exe()
        .ok()
        .as_deref()
        .and_then(Path::file_name)
        .and_then(std::ffi::OsStr::to_str)
        .map(String::from)
        .expect("Unable to parse argv[0] as String")
}
{'fraction_non_alphanumeric': 0.16022761305780173, 'fraction_numerical': 0.0005989817310572028, 'mean_word_length': 3.5380434782608696, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '3483490', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1188, 'n_words': 231}