diff --git a/src/bin/juliainstaller.rs b/src/bin/juliainstaller.rs index b34134625..539842ef7 100644 --- a/src/bin/juliainstaller.rs +++ b/src/bin/juliainstaller.rs @@ -223,9 +223,7 @@ pub fn main() -> Result<()> { }; use is_terminal::IsTerminal; use juliaup::{ - command_add::run_command_add, - command_default::run_command_default, - command_selfchannel::run_command_selfchannel, + command, config_file::JuliaupSelfConfig, get_juliaup_target, get_own_version, global_paths::get_paths, @@ -266,12 +264,6 @@ pub fn main() -> Result<()> { let mut paths = get_paths().with_context(|| "Trying to load all global paths.")?; - use juliaup::{ - command_config_backgroundselfupdate::run_command_config_backgroundselfupdate, - command_config_modifypath::run_command_config_modifypath, - command_config_startupselfupdate::run_command_config_startupselfupdate, - command_config_symlinks::run_command_config_symlinks, - }; use log::{debug, info, trace}; println!("{}", style("Welcome to Julia!").bold()); @@ -500,26 +492,28 @@ pub fn main() -> Result<()> { paths.juliaupselfconfig = self_config_path.clone(); } - run_command_config_backgroundselfupdate( + command::config::background_self_update( Some(install_choices.backgroundselfupdate), true, &paths, ) .unwrap(); - run_command_config_startupselfupdate(Some(install_choices.startupselfupdate), true, &paths) + command::config::startup_self_update(Some(install_choices.startupselfupdate), true, &paths) .unwrap(); if install_choices.modifypath { // We only run this if true so that we don't try to touch the various shell scripts at all // if this is not selected. - run_command_config_modifypath(Some(install_choices.modifypath), true, &paths).unwrap(); + command::config::modify_path(Some(install_choices.modifypath), true, &paths).unwrap(); } - run_command_config_symlinks(Some(install_choices.symlinks), true, &paths).unwrap(); - run_command_selfchannel(Some(args.juliaup_channel), &paths).unwrap(); - run_command_add(&args.default_channel, &paths) + #[cfg(not(windows))] + command::config::symlinks(Some(install_choices.symlinks), true, &paths).unwrap(); + command::selfchannel(Some(args.juliaup_channel), &paths).unwrap(); + + command::add(&args.default_channel, &paths) .with_context(|| "Failed to run `run_command_add`.")?; - run_command_default(&args.default_channel, &paths) + command::default(&args.default_channel, &paths) .with_context(|| "Failed to run `run_command_default`.")?; let symlink_path = juliaupselfbin.join("julia"); diff --git a/src/bin/juliaup.rs b/src/bin/juliaup.rs index 376809bfd..7b26096f7 100644 --- a/src/bin/juliaup.rs +++ b/src/bin/juliaup.rs @@ -1,39 +1,8 @@ use anyhow::{Context, Result}; use clap::Parser; use juliaup::cli::{ConfigSubCmd, Juliaup, OverrideSubCmd, SelfSubCmd}; -use juliaup::command_api::run_command_api; -use juliaup::command_completions::generate_completion_for_command; -use juliaup::command_config_autoinstall::run_command_config_autoinstall; -#[cfg(not(windows))] -use juliaup::command_config_symlinks::run_command_config_symlinks; -use juliaup::command_config_versionsdbupdate::run_command_config_versionsdbupdate; -use juliaup::command_default::run_command_default; -use juliaup::command_gc::run_command_gc; -use juliaup::command_info::run_command_info; -use juliaup::command_initial_setup_from_launcher::run_command_initial_setup_from_launcher; -use juliaup::command_link::run_command_link; -use juliaup::command_list::run_command_list; -use juliaup::command_override::{run_command_override_status, run_command_override_unset}; -use juliaup::command_remove::run_command_remove; -use juliaup::command_selfupdate::run_command_selfupdate; -use juliaup::command_status::run_command_status; -use juliaup::command_update::run_command_update; -use juliaup::command_update_version_db::run_command_update_version_db; +use juliaup::command; use juliaup::global_paths::get_paths; -use juliaup::{command_add::run_command_add, command_override::run_command_override_set}; -#[cfg(feature = "selfupdate")] -use juliaup::{ - command_config_backgroundselfupdate::run_command_config_backgroundselfupdate, - command_config_modifypath::run_command_config_modifypath, - command_config_startupselfupdate::run_command_config_startupselfupdate, - command_selfchannel::run_command_selfchannel, -}; - -#[cfg(feature = "selfupdate")] -use juliaup::command_selfuninstall::run_command_selfuninstall; - -#[cfg(not(feature = "selfupdate"))] -use juliaup::command_selfuninstall::run_command_selfuninstall_unavailable; use log::info; @@ -48,7 +17,7 @@ fn main() -> Result<()> { .write_style("JULIAUP_LOG_STYLE"); env_logger::init_from_env(env); - #[cfg(feature = "winpkgidentityext")] + #[cfg(all(windows, feature = "winpkgidentityext"))] { use windows::Management::Deployment::{AddPackageOptions, PackageManager}; @@ -92,68 +61,68 @@ fn main() -> Result<()> { let paths = get_paths().with_context(|| "Trying to load all global paths.")?; match args { - Juliaup::Default { channel } => run_command_default(&channel, &paths), - Juliaup::Add { channel } => run_command_add(&channel, &paths), - Juliaup::Remove { channel } => run_command_remove(&channel, &paths), - Juliaup::Status {} => run_command_status(&paths), - Juliaup::Update { channel } => run_command_update(&channel, &paths), - Juliaup::Gc { prune_linked } => run_command_gc(prune_linked, &paths), + Juliaup::Default { channel } => command::default(&channel, &paths), + Juliaup::Add { channel } => command::add(&channel, &paths), + Juliaup::Remove { channel } => command::remove(&channel, &paths), + Juliaup::Status {} => command::status(&paths), + Juliaup::Update { channel } => command::update(&channel, &paths), + Juliaup::Gc { prune_linked } => command::gc(prune_linked, &paths), Juliaup::Link { channel, target, args, - } => run_command_link(&channel, &target, &args, &paths), - Juliaup::List {} => run_command_list(&paths), + } => command::link(&channel, &target, &args, &paths), + Juliaup::List {} => command::list(&paths), Juliaup::Config(subcmd) => match subcmd { #[cfg(not(windows))] ConfigSubCmd::ChannelSymlinks { value } => { - run_command_config_symlinks(value, false, &paths) + command::config::symlinks(value, false, &paths) } #[cfg(feature = "selfupdate")] ConfigSubCmd::BackgroundSelfupdateInterval { value } => { - run_command_config_backgroundselfupdate(value, false, &paths) + command::config::background_self_update(value, false, &paths) } #[cfg(feature = "selfupdate")] ConfigSubCmd::StartupSelfupdateInterval { value } => { - run_command_config_startupselfupdate(value, false, &paths) + command::config::startup_self_update(value, false, &paths) } #[cfg(feature = "selfupdate")] ConfigSubCmd::ModifyPath { value } => { - run_command_config_modifypath(value, false, &paths) + command::config::modify_path(value, false, &paths) } ConfigSubCmd::VersionsDbUpdateInterval { value } => { - run_command_config_versionsdbupdate(value, false, &paths) + command::config::versionsdb_update(value, false, &paths) } ConfigSubCmd::AutoInstallChannels { value } => { - run_command_config_autoinstall(value, false, &paths) + command::config::autoinstall(value, false, &paths) } }, - Juliaup::Api { command } => run_command_api(&command, &paths), - Juliaup::InitialSetupFromLauncher {} => run_command_initial_setup_from_launcher(&paths), - Juliaup::UpdateVersionDb {} => run_command_update_version_db(&paths), + Juliaup::Api { command } => command::api(&command, &paths), + Juliaup::InitialSetupFromLauncher {} => command::initial_setup_from_launcher(&paths), + Juliaup::UpdateVersionDb {} => command::update_versiondb(&paths), Juliaup::OverrideSubCmd(subcmd) => match subcmd { - OverrideSubCmd::Status {} => run_command_override_status(&paths), + OverrideSubCmd::Status {} => command::r#override::status(&paths), OverrideSubCmd::Set { channel, path } => { - run_command_override_set(&paths, channel, path) + command::r#override::set(&paths, channel, path) } OverrideSubCmd::Unset { nonexistent, path } => { - run_command_override_unset(&paths, nonexistent, path) + command::r#override::unset(&paths, nonexistent, path) } }, - Juliaup::Info {} => run_command_info(&paths), + Juliaup::Info {} => command::info(&paths), #[cfg(feature = "selfupdate")] - Juliaup::SecretSelfUpdate {} => run_command_selfupdate(&paths), + Juliaup::SecretSelfUpdate {} => command::selfupdate(&paths), Juliaup::SelfSubCmd(subcmd) => match subcmd { - SelfSubCmd::Update {} => run_command_selfupdate(&paths), + SelfSubCmd::Update {} => command::selfupdate(&paths), #[cfg(feature = "selfupdate")] - SelfSubCmd::Channel { channel } => run_command_selfchannel(channel, &paths), + SelfSubCmd::Channel { channel } => command::selfchannel(channel, &paths), #[cfg(feature = "selfupdate")] - SelfSubCmd::Uninstall {} => run_command_selfuninstall(&paths), + SelfSubCmd::Uninstall {} => command::selfuninstall(&paths), #[cfg(not(feature = "selfupdate"))] - SelfSubCmd::Uninstall {} => run_command_selfuninstall_unavailable(), + SelfSubCmd::Uninstall {} => command::selfuninstall::unavailable(), }, Juliaup::Completions { shell } => { - generate_completion_for_command::(shell, "juliaup") + command::completions::generate::(shell, "juliaup") } } } diff --git a/src/command_add.rs b/src/command/add.rs similarity index 98% rename from src/command_add.rs rename to src/command/add.rs index 678e37358..501ef74a1 100644 --- a/src/command_add.rs +++ b/src/command/add.rs @@ -10,7 +10,7 @@ use crate::versions_file::load_versions_db; use anyhow::{anyhow, Context, Result}; use regex::Regex; -pub fn run_command_add(channel: &str, paths: &GlobalPaths) -> Result<()> { +pub fn run(channel: &str, paths: &GlobalPaths) -> Result<()> { // This regex is dynamically compiled, but its runtime is negligible compared to downloading Julia if Regex::new(r"^(?:pr\d+|nightly|\d+\.\d+-nightly)(?:~|$)") .unwrap() diff --git a/src/command_api.rs b/src/command/api.rs similarity index 98% rename from src/command_api.rs rename to src/command/api.rs index e20440c8d..fc8e7f039 100644 --- a/src/command_api.rs +++ b/src/command/api.rs @@ -29,7 +29,7 @@ pub struct JuliaupApiGetinfoReturn { pub other_versions: Vec, } -pub fn run_command_api(command: &str, paths: &GlobalPaths) -> Result<()> { +pub fn run(command: &str, paths: &GlobalPaths) -> Result<()> { if command != "getconfig1" { bail!("Wrong API command."); } diff --git a/src/command_completions.rs b/src/command/completions.rs similarity index 88% rename from src/command_completions.rs rename to src/command/completions.rs index e4f376f8b..848dd04ea 100644 --- a/src/command_completions.rs +++ b/src/command/completions.rs @@ -1,7 +1,7 @@ use crate::cli; use anyhow::Result; use clap::CommandFactory; -use clap_complete::{generate, Shell}; +use clap_complete::Shell; use cli::CompletionShell; use std::io; @@ -25,10 +25,8 @@ impl From for GeneratorType { } /// Generic completion generator that supports both standard shells and nushell -pub fn generate_completion_for_command( - shell: CompletionShell, - app_name: &str, -) -> Result<()> { +pub fn generate(shell: CompletionShell, app_name: &str) -> Result<()> { + use clap_complete::generate; let mut cmd = T::command(); let mut stdout = io::stdout().lock(); diff --git a/src/command_config_autoinstall.rs b/src/command/config/autoinstall.rs similarity index 88% rename from src/command_config_autoinstall.rs rename to src/command/config/autoinstall.rs index 6276fb7e9..6403859b6 100644 --- a/src/command_config_autoinstall.rs +++ b/src/command/config/autoinstall.rs @@ -1,14 +1,12 @@ -use anyhow::{anyhow, Result}; +use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; +use crate::utils::{print_juliaup_style, JuliaupMessageType}; +use anyhow::{bail, Context}; -pub fn run_command_config_autoinstall( +pub fn run( value: Option, quiet: bool, paths: &crate::global_paths::GlobalPaths, -) -> Result<()> { - use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; - use crate::utils::{print_juliaup_style, JuliaupMessageType}; - use anyhow::Context; - +) -> anyhow::Result<()> { match value { Some(value_str) => { let mut config_file = load_mut_config_db(paths) @@ -19,12 +17,10 @@ pub fn run_command_config_autoinstall( "true" => Some(true), "false" => Some(false), "default" => None, - _ => { - return Err(anyhow!( + _ => bail!( "Invalid value '{}'. Valid values are: true, false, default (to unset the property)", value_str - )) - } + ), }; if new_value != config_file.data.settings.auto_install_channels { diff --git a/src/command_config_backgroundselfupdate.rs b/src/command/config/background_self_update.rs similarity index 90% rename from src/command_config_backgroundselfupdate.rs rename to src/command/config/background_self_update.rs index 171b9aac3..d89016db6 100644 --- a/src/command_config_backgroundselfupdate.rs +++ b/src/command/config/background_self_update.rs @@ -1,17 +1,13 @@ -#[cfg(feature = "selfupdate")] +use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; use crate::utils::{print_juliaup_style, JuliaupMessageType}; -#[cfg(feature = "selfupdate")] -use anyhow::Result; +use anyhow::{bail, Context}; -#[cfg(feature = "selfupdate")] -pub fn run_command_config_backgroundselfupdate( +pub fn run( value: Option, quiet: bool, paths: &crate::global_paths::GlobalPaths, -) -> Result<()> { - use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; +) -> anyhow::Result<()> { use crate::operations::{install_background_selfupdate, uninstall_background_selfupdate}; - use anyhow::{bail, Context}; match value { Some(value) => { diff --git a/src/command/config/mod.rs b/src/command/config/mod.rs new file mode 100644 index 000000000..dcad23fde --- /dev/null +++ b/src/command/config/mod.rs @@ -0,0 +1,25 @@ +mod autoinstall; +pub use autoinstall::run as autoinstall; + +#[cfg(feature = "selfupdate")] +mod background_self_update; +#[cfg(feature = "selfupdate")] +pub use background_self_update::run as background_self_update; + +#[cfg(feature = "selfupdate")] +mod modify_path; +#[cfg(feature = "selfupdate")] +pub use modify_path::run as modify_path; + +#[cfg(feature = "selfupdate")] +mod startup_self_update; +#[cfg(feature = "selfupdate")] +pub use startup_self_update::run as startup_self_update; + +#[cfg(not(windows))] +mod symlinks; +#[cfg(not(windows))] +pub use symlinks::run as symlinks; + +mod versionsdb_update; +pub use versionsdb_update::run as versionsdb_update; diff --git a/src/command_config_modifypath.rs b/src/command/config/modify_path.rs similarity index 89% rename from src/command_config_modifypath.rs rename to src/command/config/modify_path.rs index df94b85ee..602d90bd0 100644 --- a/src/command_config_modifypath.rs +++ b/src/command/config/modify_path.rs @@ -1,15 +1,15 @@ -#[cfg(feature = "selfupdate")] -pub fn run_command_config_modifypath( +use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; +use crate::utils::{print_juliaup_style, JuliaupMessageType}; +use anyhow::Context; + +pub fn run( value: Option, quiet: bool, paths: &crate::global_paths::GlobalPaths, ) -> anyhow::Result<()> { - use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; use crate::operations::{ add_binfolder_to_path_in_shell_scripts, remove_binfolder_from_path_in_shell_scripts, }; - use crate::utils::{print_juliaup_style, JuliaupMessageType}; - use anyhow::Context; match value { Some(value) => { diff --git a/src/command_config_startupselfupdate.rs b/src/command/config/startup_self_update.rs similarity index 89% rename from src/command_config_startupselfupdate.rs rename to src/command/config/startup_self_update.rs index 1a4d29d1a..1f53be6c9 100644 --- a/src/command_config_startupselfupdate.rs +++ b/src/command/config/startup_self_update.rs @@ -1,17 +1,12 @@ -#[cfg(feature = "selfupdate")] +use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; use crate::utils::{print_juliaup_style, JuliaupMessageType}; -#[cfg(feature = "selfupdate")] -use anyhow::Result; +use anyhow::{bail, Context}; -#[cfg(feature = "selfupdate")] -pub fn run_command_config_startupselfupdate( +pub fn run( value: Option, quiet: bool, paths: &crate::global_paths::GlobalPaths, -) -> Result<()> { - use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; - use anyhow::{bail, Context}; - +) -> anyhow::Result<()> { match value { Some(value) => { if value < 0 { diff --git a/src/command_config_symlinks.rs b/src/command/config/symlinks.rs similarity index 86% rename from src/command_config_symlinks.rs rename to src/command/config/symlinks.rs index d55b99b3c..bcfebd096 100644 --- a/src/command_config_symlinks.rs +++ b/src/command/config/symlinks.rs @@ -1,16 +1,13 @@ -#[cfg(not(windows))] -use anyhow::Result; +use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; +use crate::utils::{print_juliaup_style, JuliaupMessageType}; +use anyhow::Context; -#[cfg(not(windows))] -pub fn run_command_config_symlinks( +pub fn run( value: Option, quiet: bool, paths: &crate::global_paths::GlobalPaths, -) -> Result<()> { - use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; +) -> anyhow::Result<()> { use crate::operations::{create_symlink, remove_symlink}; - use crate::utils::{print_juliaup_style, JuliaupMessageType}; - use anyhow::Context; match value { Some(value) => { @@ -59,7 +56,7 @@ pub fn run_command_config_symlinks( print_juliaup_style( "Configure", &format!( - "Property 'channelsymlinks' set to '{}'", + "Property 'create_channel_symlinks' set to '{}'", config_file.data.settings.create_channel_symlinks ), JuliaupMessageType::Success, diff --git a/src/command_config_versionsdbupdate.rs b/src/command/config/versionsdb_update.rs similarity index 95% rename from src/command_config_versionsdbupdate.rs rename to src/command/config/versionsdb_update.rs index f37f63091..c406423d3 100644 --- a/src/command_config_versionsdbupdate.rs +++ b/src/command/config/versionsdb_update.rs @@ -1,12 +1,12 @@ use crate::config_file::{load_config_db, load_mut_config_db, save_config_db}; use crate::utils::{print_juliaup_style, JuliaupMessageType}; -use anyhow::{bail, Context, Result}; +use anyhow::{bail, Context}; -pub fn run_command_config_versionsdbupdate( +pub fn run( value: Option, quiet: bool, paths: &crate::global_paths::GlobalPaths, -) -> Result<()> { +) -> anyhow::Result<()> { match value { Some(value) => { if value < 0 { diff --git a/src/command_default.rs b/src/command/default.rs similarity index 94% rename from src/command_default.rs rename to src/command/default.rs index 161b8f463..094f22627 100644 --- a/src/command_default.rs +++ b/src/command/default.rs @@ -4,7 +4,7 @@ use crate::versions_file::load_versions_db; use crate::{config_file::*, global_paths::GlobalPaths}; use anyhow::{bail, Context, Result}; -pub fn run_command_default(channel: &str, paths: &GlobalPaths) -> Result<()> { +pub fn run(channel: &str, paths: &GlobalPaths) -> Result<()> { let mut config_file = load_mut_config_db(paths) .with_context(|| "`default` command failed to load configuration data.")?; diff --git a/src/command_gc.rs b/src/command/gc.rs similarity index 86% rename from src/command_gc.rs rename to src/command/gc.rs index 19c12dd2f..d9e4b46de 100644 --- a/src/command_gc.rs +++ b/src/command/gc.rs @@ -3,7 +3,7 @@ use crate::global_paths::GlobalPaths; use crate::operations::garbage_collect_versions; use anyhow::{Context, Result}; -pub fn run_command_gc(prune_linked: bool, paths: &GlobalPaths) -> Result<()> { +pub fn run(prune_linked: bool, paths: &GlobalPaths) -> Result<()> { let mut config_file = load_mut_config_db(paths) .with_context(|| "`gc` command failed to load configuration data.")?; diff --git a/src/command_info.rs b/src/command/info.rs similarity index 98% rename from src/command_info.rs rename to src/command/info.rs index 31b8919d0..1724d0c1b 100644 --- a/src/command_info.rs +++ b/src/command/info.rs @@ -8,7 +8,7 @@ use crate::{get_bundled_dbversion, global_paths::GlobalPaths}; use crate::{get_juliaup_target, get_own_version}; use anyhow::{bail, Context, Result}; -pub fn run_command_info(paths: &GlobalPaths) -> Result<()> { +pub fn run(paths: &GlobalPaths) -> Result<()> { #[cfg(feature = "selfupdate")] let config_file = load_config_db(paths, None).with_context(|| { "`run_command_update_version_db` command failed to load configuration db." diff --git a/src/command/initial_setup_from_launcher.rs b/src/command/initial_setup_from_launcher.rs new file mode 100644 index 000000000..779465bc0 --- /dev/null +++ b/src/command/initial_setup_from_launcher.rs @@ -0,0 +1,9 @@ +use crate::{command, global_paths::GlobalPaths}; +use anyhow::{Context, Result}; + +pub fn run(paths: &GlobalPaths) -> Result<()> { + command::add("release", paths) + .with_context(|| "Failed to run `run_command_add` from the `run_command_initial_setup_from_launcher` command.")?; + + Ok(()) +} diff --git a/src/command_link.rs b/src/command/link.rs similarity index 97% rename from src/command_link.rs rename to src/command/link.rs index c20cadc08..7d0901305 100644 --- a/src/command_link.rs +++ b/src/command/link.rs @@ -11,12 +11,7 @@ use anyhow::{bail, Context, Result}; use path_absolutize::Absolutize; use std::path::Path; -pub fn run_command_link( - channel: &str, - target: &str, - args: &[String], - paths: &GlobalPaths, -) -> Result<()> { +pub fn run(channel: &str, target: &str, args: &[String], paths: &GlobalPaths) -> Result<()> { let mut config_file = load_mut_config_db(paths) .with_context(|| "`link` command failed to load configuration data.")?; diff --git a/src/command_list.rs b/src/command/list.rs similarity index 96% rename from src/command_list.rs rename to src/command/list.rs index b1cdd0402..272e490d0 100644 --- a/src/command_list.rs +++ b/src/command/list.rs @@ -16,7 +16,7 @@ struct ChannelRow { version: String, } -pub fn run_command_list(paths: &GlobalPaths) -> Result<()> { +pub fn run(paths: &GlobalPaths) -> Result<()> { let versiondb_data = load_versions_db(paths).with_context(|| "`list` command failed to load versions db.")?; diff --git a/src/command/mod.rs b/src/command/mod.rs new file mode 100644 index 000000000..69eb07698 --- /dev/null +++ b/src/command/mod.rs @@ -0,0 +1,52 @@ +mod add; +pub use add::run as add; + +mod api; +pub use api::run as api; + +pub mod completions; +pub mod config; + +mod default; +pub use default::run as default; + +mod gc; +pub use gc::run as gc; + +mod info; +pub use info::run as info; + +mod initial_setup_from_launcher; +pub use initial_setup_from_launcher::run as initial_setup_from_launcher; + +mod link; +pub use link::run as link; + +mod list; +pub use list::run as list; + +pub mod r#override; + +mod remove; +pub use remove::run as remove; + +#[cfg(feature = "selfupdate")] +mod selfchannel; +#[cfg(feature = "selfupdate")] +pub use selfchannel::run as selfchannel; + +pub mod selfuninstall; +#[cfg(feature = "selfupdate")] +pub use selfuninstall::run as selfuninstall; + +mod selfupdate; +pub use selfupdate::run as selfupdate; + +mod status; +pub use status::run as status; + +mod update; +pub use update::run as update; + +mod update_versiondb; +pub use update_versiondb::run as update_versiondb; diff --git a/src/command_override.rs b/src/command/override.rs similarity index 92% rename from src/command_override.rs rename to src/command/override.rs index 4e86de397..aa09e6455 100644 --- a/src/command_override.rs +++ b/src/command/override.rs @@ -23,7 +23,7 @@ struct OverrideRow { channel: String, } -pub fn run_command_override_status(paths: &GlobalPaths) -> Result<()> { +pub fn status(paths: &GlobalPaths) -> Result<()> { let config_file = load_config_db(paths, None) .with_context(|| "`override status` command failed to load configuration file.")?; @@ -57,11 +57,7 @@ pub fn run_command_override_status(paths: &GlobalPaths) -> Result<()> { Ok(()) } -pub fn run_command_override_set( - paths: &GlobalPaths, - channel: String, - path: Option, -) -> Result<()> { +pub fn set(paths: &GlobalPaths, channel: String, path: Option) -> Result<()> { let mut config_file = load_mut_config_db(paths) .with_context(|| "`override set` command failed to load configuration data.")?; @@ -124,11 +120,7 @@ pub fn run_command_override_set( Ok(()) } -pub fn run_command_override_unset( - paths: &GlobalPaths, - nonexistent: bool, - path: Option, -) -> Result<()> { +pub fn unset(paths: &GlobalPaths, nonexistent: bool, path: Option) -> Result<()> { let mut config_file = load_mut_config_db(paths) .with_context(|| "`override unset` command failed to load configuration data.")?; diff --git a/src/command_remove.rs b/src/command/remove.rs similarity index 95% rename from src/command_remove.rs rename to src/command/remove.rs index cb286f64c..2b99fdf64 100644 --- a/src/command_remove.rs +++ b/src/command/remove.rs @@ -1,14 +1,14 @@ #[cfg(not(windows))] use crate::operations::remove_symlink; -use crate::utils::{print_juliaup_style, JuliaupMessageType}; use crate::{ config_file::{load_mut_config_db, save_config_db, JuliaupConfigChannel}, global_paths::GlobalPaths, operations::garbage_collect_versions, + utils::{print_juliaup_style, JuliaupMessageType}, }; use anyhow::{bail, Context, Result}; -pub fn run_command_remove(channel: &str, paths: &GlobalPaths) -> Result<()> { +pub fn run(channel: &str, paths: &GlobalPaths) -> Result<()> { let mut config_file = load_mut_config_db(paths) .with_context(|| "`remove` command failed to load configuration data.")?; diff --git a/src/command_selfchannel.rs b/src/command/selfchannel.rs similarity index 90% rename from src/command_selfchannel.rs rename to src/command/selfchannel.rs index b7da7617b..647bcdbee 100644 --- a/src/command_selfchannel.rs +++ b/src/command/selfchannel.rs @@ -1,8 +1,6 @@ -#[cfg(feature = "selfupdate")] use anyhow::Result; -#[cfg(feature = "selfupdate")] -pub fn run_command_selfchannel( +pub fn run( channel: Option, paths: &crate::global_paths::GlobalPaths, ) -> Result<()> { diff --git a/src/command_selfuninstall.rs b/src/command/selfuninstall.rs similarity index 84% rename from src/command_selfuninstall.rs rename to src/command/selfuninstall.rs index 493e0f612..de0e14730 100644 --- a/src/command_selfuninstall.rs +++ b/src/command/selfuninstall.rs @@ -1,15 +1,11 @@ -#[cfg(feature = "selfupdate")] use anyhow::Result; #[cfg(feature = "selfupdate")] -pub fn run_command_selfuninstall(paths: &crate::global_paths::GlobalPaths) -> Result<()> { +pub fn run(paths: &crate::global_paths::GlobalPaths) -> Result<()> { use dialoguer::Confirm; use crate::{ - command_config_backgroundselfupdate::run_command_config_backgroundselfupdate, - command_config_modifypath::run_command_config_modifypath, - command_config_startupselfupdate::run_command_config_startupselfupdate, - command_config_symlinks::run_command_config_symlinks, + command, utils::{print_juliaup_style, JuliaupMessageType}, }; @@ -23,25 +19,25 @@ pub fn run_command_selfuninstall(paths: &crate::global_paths::GlobalPaths) -> Re } eprint!("Removing background self update task."); - match run_command_config_backgroundselfupdate(Some(0), true, paths) { + match command::config::background_self_update(Some(0), true, paths) { Ok(_) => eprintln!(" Success."), Err(_) => eprintln!(" Failed."), }; eprint!("Removing startup self update configuration."); - match run_command_config_startupselfupdate(Some(0), true, paths) { + match command::config::startup_self_update(Some(0), true, paths) { Ok(_) => eprintln!(" Success."), Err(_) => eprintln!(" Failed."), }; eprint!("Removing PATH modifications in startup scripts."); - match run_command_config_modifypath(Some(false), true, paths) { + match command::config::modify_path(Some(false), true, paths) { Ok(_) => eprintln!(" Success."), Err(_) => eprintln!(" Failed."), }; eprint!("Removing symlinks."); - match run_command_config_symlinks(Some(false), true, paths) { + match command::config::symlinks(Some(false), true, paths) { Ok(_) => eprintln!(" Success."), Err(_) => eprintln!(" Failed."), }; @@ -124,10 +120,7 @@ pub fn run_command_selfuninstall(paths: &crate::global_paths::GlobalPaths) -> Re } #[cfg(not(feature = "selfupdate"))] -use anyhow::Result; - -#[cfg(not(feature = "selfupdate"))] -pub fn run_command_selfuninstall_unavailable() -> Result<()> { +pub fn unavailable() -> Result<()> { eprintln!( "Self uninstall command is unavailable in this variant of Juliaup. This software was built with the intention of distributing it diff --git a/src/command_selfupdate.rs b/src/command/selfupdate.rs similarity index 95% rename from src/command_selfupdate.rs rename to src/command/selfupdate.rs index d14870cb0..009510475 100644 --- a/src/command_selfupdate.rs +++ b/src/command/selfupdate.rs @@ -3,7 +3,7 @@ use crate::operations::update_version_db; use anyhow::{Context, Result}; #[cfg(feature = "selfupdate")] -pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> { +pub fn run(paths: &GlobalPaths) -> Result<()> { use crate::config_file::{load_mut_config_db, save_config_db}; use crate::operations::{download_extract_sans_parent, download_juliaup_version}; use crate::utils::get_juliaserver_base_url; @@ -90,8 +90,8 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> { Ok(()) } -#[cfg(feature = "windowsstore")] -pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> { +#[cfg(all(windows, feature = "windowsstore"))] +pub fn run(paths: &GlobalPaths) -> Result<()> { use windows::{ core::Interface, Win32::{System::Console::GetConsoleWindow, UI::Shell::IInitializeWithWindow}, @@ -145,7 +145,7 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> { } #[cfg(not(any(feature = "windowsstore", feature = "selfupdate")))] -pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> { +pub fn run(paths: &GlobalPaths) -> Result<()> { update_version_db(&None, paths).with_context(|| "Failed to update versions db.")?; Ok(()) } diff --git a/src/command_status.rs b/src/command/status.rs similarity index 91% rename from src/command_status.rs rename to src/command/status.rs index b60db3595..43e437448 100644 --- a/src/command_status.rs +++ b/src/command/status.rs @@ -1,15 +1,14 @@ -use crate::config_file::load_config_db; -use crate::config_file::{JuliaupConfigChannel, JuliaupReadonlyConfigFile}; -use crate::global_paths::GlobalPaths; -use crate::jsonstructs_versionsdb::JuliaupVersionDB; -use crate::versions_file::load_versions_db; +use crate::{ + config_file::load_config_db, + config_file::{JuliaupConfigChannel, JuliaupReadonlyConfigFile}, + global_paths::GlobalPaths, + jsonstructs_versionsdb::JuliaupVersionDB, + versions_file::load_versions_db, +}; use anyhow::{Context, Result}; -use cli_table::format::HorizontalLine; -use cli_table::format::Separator; -use cli_table::ColorChoice; use cli_table::{ - format::{Border, Justify}, - print_stdout, Table, WithTitle, + format::{Border, HorizontalLine, Justify, Separator}, + print_stdout, ColorChoice, Table, WithTitle, }; use itertools::Itertools; use numeric_sort::cmp; @@ -115,7 +114,7 @@ struct ChannelRow { update: String, } -pub fn run_command_status(paths: &GlobalPaths) -> Result<()> { +pub fn run(paths: &GlobalPaths) -> Result<()> { let config_file = load_config_db(paths, None) .with_context(|| "`status` command failed to load configuration file.")?; diff --git a/src/command_update.rs b/src/command/update.rs similarity index 98% rename from src/command_update.rs rename to src/command/update.rs index 3a1d5d8e7..2cced1cd7 100644 --- a/src/command_update.rs +++ b/src/command/update.rs @@ -135,7 +135,7 @@ fn update_channel( Ok(()) } -pub fn run_command_update(channel: &Option, paths: &GlobalPaths) -> Result<()> { +pub fn run(channel: &Option, paths: &GlobalPaths) -> Result<()> { update_version_db(channel, paths).with_context(|| "Failed to update versions db.")?; let version_db = diff --git a/src/command_update_version_db.rs b/src/command/update_versiondb.rs similarity index 73% rename from src/command_update_version_db.rs rename to src/command/update_versiondb.rs index bc838347f..5b9e585ed 100644 --- a/src/command_update_version_db.rs +++ b/src/command/update_versiondb.rs @@ -1,7 +1,7 @@ use crate::{global_paths::GlobalPaths, operations::update_version_db}; use anyhow::{Context, Result}; -pub fn run_command_update_version_db(paths: &GlobalPaths) -> Result<()> { +pub fn run(paths: &GlobalPaths) -> Result<()> { update_version_db(&None, paths).with_context(|| "Failed to update version db.")?; Ok(()) diff --git a/src/command_initial_setup_from_launcher.rs b/src/command_initial_setup_from_launcher.rs deleted file mode 100644 index d97e13275..000000000 --- a/src/command_initial_setup_from_launcher.rs +++ /dev/null @@ -1,9 +0,0 @@ -use crate::{command_add::run_command_add, global_paths::GlobalPaths}; -use anyhow::{Context, Result}; - -pub fn run_command_initial_setup_from_launcher(paths: &GlobalPaths) -> Result<()> { - run_command_add("release", paths) - .with_context(|| "Failed to run `run_command_add` from the `run_command_initial_setup_from_launcher` command.")?; - - Ok(()) -} diff --git a/src/lib.rs b/src/lib.rs index 71caa966a..8c4a69906 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,30 +1,9 @@ use anyhow::Context; +pub mod command; + pub mod cli; pub mod cli_styles; -pub mod command_add; -pub mod command_api; -pub mod command_completions; -pub mod command_config_autoinstall; -pub mod command_config_backgroundselfupdate; -pub mod command_config_modifypath; -pub mod command_config_startupselfupdate; -pub mod command_config_symlinks; -pub mod command_config_versionsdbupdate; -pub mod command_default; -pub mod command_gc; -pub mod command_info; -pub mod command_initial_setup_from_launcher; -pub mod command_link; -pub mod command_list; -pub mod command_override; -pub mod command_remove; -pub mod command_selfchannel; -pub mod command_selfuninstall; -pub mod command_selfupdate; -pub mod command_status; -pub mod command_update; -pub mod command_update_version_db; pub mod config_file; pub mod global_paths; pub mod jsonstructs_versionsdb;