pub fn run_cli<TEnvironment: Environment>(
    args: CliArgs,
    environment: &TEnvironment,
    cache: &Cache<TEnvironment>,
    plugin_resolver: &PluginResolver<TEnvironment>,
    plugin_pools: Arc<PluginPools<TEnvironment>>,
) -> Result<(), ErrBox> {
    // todo: reduce code duplication in this function
    match &args.sub_command {
        SubCommand::Help(help_text) => output_help(&args, cache, environment, plugin_resolver, help_text),
        SubCommand::License => output_license(&args, cache, environment, plugin_resolver),
        SubCommand::EditorInfo => output_editor_info(&args, cache, environment, plugin_resolver),
        SubCommand::EditorService(cmd) => run_editor_service(&args, cache, environment, plugin_resolver, plugin_pools, cmd),
        SubCommand::ClearCache => clear_cache(environment),
        SubCommand::Init => init_config_file(environment, &args.config),
        SubCommand::Version => output_version(environment),
        SubCommand::StdInFmt(cmd) => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            plugin_pools.set_plugins(plugins);
            // if the path is absolute, then apply exclusion rules
            if environment.is_absolute_path(&cmd.file_path) {
                let file_paths = get_and_resolve_file_paths(&config, &args, environment)?;
                // canonicalize the file path, then check if it's in the list of file paths.
                match environment.canonicalize(&cmd.file_path) {
                    Ok(resolved_file_path) => {
                        // log the file text as-is since it's not in the list of files to format
                        if !file_paths.contains(&resolved_file_path) {
                            environment.log_silent(&cmd.file_text);
                            return Ok(());
                        }
                    }
                    Err(err) => return err!("Error canonicalizing file {}: {}", cmd.file_path.display(), err.to_string()),
                }
            }
            output_stdin_format(&cmd.file_path, &cmd.file_text, environment, plugin_pools)
        }
        SubCommand::OutputResolvedConfig => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            output_resolved_config(plugins, environment)
        }
        SubCommand::OutputFilePaths => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            let file_paths = get_and_resolve_file_paths(&config, &args, environment)?;
            let file_paths_by_plugin = get_file_paths_by_plugin(&plugins, file_paths);
            output_file_paths(file_paths_by_plugin.values().flat_map(|x| x.iter()), environment);
            Ok(())
        }
        SubCommand::OutputFormatTimes => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            let file_paths = get_and_resolve_file_paths(&config, &args, environment)?;
            let file_paths_by_plugin = get_file_paths_by_plugin_and_err_if_empty(&plugins, file_paths)?;
            plugin_pools.set_plugins(plugins);
            output_format_times(file_paths_by_plugin, environment, plugin_pools)
        }
        SubCommand::Check => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            let file_paths = get_and_resolve_file_paths(&config, &args, environment)?;
            let file_paths_by_plugin = get_file_paths_by_plugin_and_err_if_empty(&plugins, file_paths)?;
            plugin_pools.set_plugins(plugins);

            let incremental_file = get_incremental_file(&args, &config, &cache, &plugin_pools, &environment);
            check_files(file_paths_by_plugin, environment, plugin_pools, incremental_file)
        }
        SubCommand::Fmt => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            let file_paths = get_and_resolve_file_paths(&config, &args, environment)?;
            let file_paths_by_plugin = get_file_paths_by_plugin_and_err_if_empty(&plugins, file_paths)?;
            plugin_pools.set_plugins(plugins);

            let incremental_file = get_incremental_file(&args, &config, &cache, &plugin_pools, &environment);
            format_files(file_paths_by_plugin, environment, plugin_pools, incremental_file)
        }
        #[cfg(target_os = "windows")]
        SubCommand::Hidden(hidden_command) => {
            match hidden_command {
                super::HiddenSubCommand::WindowsInstall(install_path) => super::install::handle_windows_install(environment, &install_path),
                super::HiddenSubCommand::WindowsUninstall(install_path) => super::install::handle_windows_uninstall(environment, &install_path),
            }
        }
    }
}
// TODO: probably a lot of these functions could be moved into new files
probably a lot of these functions could be moved into new files
probably a lot of these functions could be moved into new files
pub fn run_cli<TEnvironment: Environment>(
    args: CliArgs,
    environment: &TEnvironment,
    cache: &Cache<TEnvironment>,
    plugin_resolver: &PluginResolver<TEnvironment>,
    plugin_pools: Arc<PluginPools<TEnvironment>>,
) -> Result<(), ErrBox> {
    // todo: reduce code duplication in this function
    match &args.sub_command {
        SubCommand::Help(help_text) => output_help(&args, cache, environment, plugin_resolver, help_text),
        SubCommand::License => output_license(&args, cache, environment, plugin_resolver),
        SubCommand::EditorInfo => output_editor_info(&args, cache, environment, plugin_resolver),
        SubCommand::EditorService(cmd) => run_editor_service(&args, cache, environment, plugin_resolver, plugin_pools, cmd),
        SubCommand::ClearCache => clear_cache(environment),
        SubCommand::Init => init_config_file(environment, &args.config),
        SubCommand::Version => output_version(environment),
        SubCommand::StdInFmt(cmd) => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            plugin_pools.set_plugins(plugins);
            // if the path is absolute, then apply exclusion rules
            if environment.is_absolute_path(&cmd.file_path) {
                let file_paths = get_and_resolve_file_paths(&config, &args, environment)?;
                // canonicalize the file path, then check if it's in the list of file paths.
                match environment.canonicalize(&cmd.file_path) {
                    Ok(resolved_file_path) => {
                        // log the file text as-is since it's not in the list of files to format
                        if !file_paths.contains(&resolved_file_path) {
                            environment.log_silent(&cmd.file_text);
                            return Ok(());
                        }
                    }
                    Err(err) => return err!("Error canonicalizing file {}: {}", cmd.file_path.display(), err.to_string()),
                }
            }
            output_stdin_format(&cmd.file_path, &cmd.file_text, environment, plugin_pools)
        }
        SubCommand::OutputResolvedConfig => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            output_resolved_config(plugins, environment)
        }
        SubCommand::OutputFilePaths => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            let file_paths = get_and_resolve_file_paths(&config, &args, environment)?;
            let file_paths_by_plugin = get_file_paths_by_plugin(&plugins, file_paths);
            output_file_paths(file_paths_by_plugin.values().flat_map(|x| x.iter()), environment);
            Ok(())
        }
        SubCommand::OutputFormatTimes => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            let file_paths = get_and_resolve_file_paths(&config, &args, environment)?;
            let file_paths_by_plugin = get_file_paths_by_plugin_and_err_if_empty(&plugins, file_paths)?;
            plugin_pools.set_plugins(plugins);
            output_format_times(file_paths_by_plugin, environment, plugin_pools)
        }
        SubCommand::Check => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            let file_paths = get_and_resolve_file_paths(&config, &args, environment)?;
            let file_paths_by_plugin = get_file_paths_by_plugin_and_err_if_empty(&plugins, file_paths)?;
            plugin_pools.set_plugins(plugins);
            let incremental_file = get_incremental_file(&args, &config, &cache, &plugin_pools, &environment);
            check_files(file_paths_by_plugin, environment, plugin_pools, incremental_file)
        }
        SubCommand::Fmt => {
            let config = resolve_config_from_args(&args, cache, environment)?;
            let plugins = resolve_plugins_and_err_if_empty(&config, environment, plugin_resolver)?;
            let file_paths = get_and_resolve_file_paths(&config, &args, environment)?;
            let file_paths_by_plugin = get_file_paths_by_plugin_and_err_if_empty(&plugins, file_paths)?;
            plugin_pools.set_plugins(plugins);
            let incremental_file = get_incremental_file(&args, &config, &cache, &plugin_pools, &environment);
            format_files(file_paths_by_plugin, environment, plugin_pools, incremental_file)
        }
        #[cfg(target_os = "windows")]
        SubCommand::Hidden(hidden_command) => {
            match hidden_command {
                super::HiddenSubCommand::WindowsInstall(install_path) => super::install::handle_windows_install(environment, &install_path),
                super::HiddenSubCommand::WindowsUninstall(install_path) => super::install::handle_windows_uninstall(environment, &install_path),
            }
        }
    }
}
pub fn run_cli < TEnvironment : Environment > ( args : CliArgs , environment : & TEnvironment , cache : & Cache < TEnvironment > , plugin_resolver : & PluginResolver < TEnvironment > , plugin_pools : Arc < PluginPools < TEnvironment > > , ) -> Result < ( ) , ErrBox > { // todo: reduce code duplication in this function match & args . sub_command { SubCommand :: Help ( help_text ) => output_help ( & args , cache , environment , plugin_resolver , help_text ) , SubCommand :: License => output_license ( & args , cache , environment , plugin_resolver ) , SubCommand :: EditorInfo => output_editor_info ( & args , cache , environment , plugin_resolver ) , SubCommand :: EditorService ( cmd ) => run_editor_service ( & args , cache , environment , plugin_resolver , plugin_pools , cmd ) , SubCommand :: ClearCache => clear_cache ( environment ) , SubCommand :: Init => init_config_file ( environment , & args . config ) , SubCommand :: Version => output_version ( environment ) , SubCommand :: StdInFmt ( cmd ) => { let config = resolve_config_from_args ( & args , cache , environment ) ? ; let plugins = resolve_plugins_and_err_if_empty ( & config , environment , plugin_resolver ) ? ; plugin_pools . set_plugins ( plugins ) ; // if the path is absolute, then apply exclusion rules if environment . is_absolute_path ( & cmd . file_path ) { let file_paths = get_and_resolve_file_paths ( & config , & args , environment ) ? ; // canonicalize the file path, then check if it's in the list of file paths. match environment . canonicalize ( & cmd . file_path ) { Ok ( resolved_file_path ) => { // log the file text as-is since it's not in the list of files to format if ! file_paths . contains ( & resolved_file_path ) { environment . log_silent ( & cmd . file_text ) ; return Ok ( ( ) ) ; } } Err ( err ) => return err ! ( " " cmd file_path display ( ) err to_string ( ) ) , } } output_stdin_format ( & cmd . file_path , & cmd . file_text , environment , plugin_pools ) } SubCommand :: OutputResolvedConfig => { let config = resolve_config_from_args ( & args , cache , environment ) ? ; let plugins = resolve_plugins_and_err_if_empty ( & config , environment , plugin_resolver ) ? ; output_resolved_config ( plugins , environment ) } SubCommand :: OutputFilePaths => { let config = resolve_config_from_args ( & args , cache , environment ) ? ; let plugins = resolve_plugins_and_err_if_empty ( & config , environment , plugin_resolver ) ? ; let file_paths = get_and_resolve_file_paths ( & config , & args , environment ) ? ; let file_paths_by_plugin = get_file_paths_by_plugin ( & plugins , file_paths ) ; output_file_paths ( file_paths_by_plugin . values ( ) . flat_map ( | x | x . iter ( ) ) , environment ) ; Ok ( ( ) ) } SubCommand :: OutputFormatTimes => { let config = resolve_config_from_args ( & args , cache , environment ) ? ; let plugins = resolve_plugins_and_err_if_empty ( & config , environment , plugin_resolver ) ? ; let file_paths = get_and_resolve_file_paths ( & config , & args , environment ) ? ; let file_paths_by_plugin = get_file_paths_by_plugin_and_err_if_empty ( & plugins , file_paths ) ? ; plugin_pools . set_plugins ( plugins ) ; output_format_times ( file_paths_by_plugin , environment , plugin_pools ) } SubCommand :: Check => { let config = resolve_config_from_args ( & args , cache , environment ) ? ; let plugins = resolve_plugins_and_err_if_empty ( & config , environment , plugin_resolver ) ? ; let file_paths = get_and_resolve_file_paths ( & config , & args , environment ) ? ; let file_paths_by_plugin = get_file_paths_by_plugin_and_err_if_empty ( & plugins , file_paths ) ? ; plugin_pools . set_plugins ( plugins ) ; let incremental_file = get_incremental_file ( & args , & config , & cache , & plugin_pools , & environment ) ; check_files ( file_paths_by_plugin , environment , plugin_pools , incremental_file ) } SubCommand :: Fmt => { let config = resolve_config_from_args ( & args , cache , environment ) ? ; let plugins = resolve_plugins_and_err_if_empty ( & config , environment , plugin_resolver ) ? ; let file_paths = get_and_resolve_file_paths ( & config , & args , environment ) ? ; let file_paths_by_plugin = get_file_paths_by_plugin_and_err_if_empty ( & plugins , file_paths ) ? ; plugin_pools . set_plugins ( plugins ) ; let incremental_file = get_incremental_file ( & args , & config , & cache , & plugin_pools , & environment ) ; format_files ( file_paths_by_plugin , environment , plugin_pools , incremental_file ) } # [ cfg ( target_os " " ) ] SubCommand :: Hidden ( hidden_command ) => { match hidden_command { super :: HiddenSubCommand :: WindowsInstall ( install_path ) => super :: install :: handle_windows_install ( environment , & install_path ) , super :: HiddenSubCommand :: WindowsUninstall ( install_path ) => super :: install :: handle_windows_uninstall ( environment , & install_path ) , } } } }
TODO: probably a lot of these functions could be moved into new files
TODO : probably a lot of these functions could be moved into new files
args
CliArgs
environment
&TEnvironment
cache
&Cache<TEnvironment>
plugin_resolver
&PluginResolver<TEnvironment>
plugin_pools
Arc<PluginPools<TEnvironment>>