Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/bin/juliainstaller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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");
Expand Down
89 changes: 29 additions & 60 deletions src/bin/juliaup.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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"))]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing the feature powerset with cargo-hack. Since the windows crate is only available on windows, it threw a compile error.

{
use windows::Management::Deployment::{AddPackageOptions, PackageManager};

Expand Down Expand Up @@ -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::<Juliaup>(shell, "juliaup")
command::completions::generate::<Juliaup>(shell, "juliaup")
}
}
}
2 changes: 1 addition & 1 deletion src/command_add.rs → src/command/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/command_api.rs → src/command/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct JuliaupApiGetinfoReturn {
pub other_versions: Vec<JuliaupChannelInfo>,
}

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.");
}
Expand Down
8 changes: 3 additions & 5 deletions src/command_completions.rs → src/command/completions.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -25,10 +25,8 @@ impl From<CompletionShell> for GeneratorType {
}

/// Generic completion generator that supports both standard shells and nushell
pub fn generate_completion_for_command<T: CommandFactory>(
shell: CompletionShell,
app_name: &str,
) -> Result<()> {
pub fn generate<T: CommandFactory>(shell: CompletionShell, app_name: &str) -> Result<()> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command::completions::generate is self-explanatory in code

use clap_complete::generate;
let mut cmd = T::command();
let mut stdout = io::stdout().lock();

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String>,
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)
Expand All @@ -19,12 +17,10 @@ pub fn run_command_config_autoinstall(
"true" => Some(true),
"false" => Some(false),
"default" => None,
_ => {
return Err(anyhow!(
_ => bail!(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to bail! for consistency with other parts of the codebase

"Invalid value '{}'. Valid values are: true, false, default (to unset the property)",
value_str
))
}
),
};

if new_value != config_file.data.settings.auto_install_channels {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<i64>,
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) => {
Expand Down
25 changes: 25 additions & 0 deletions src/command/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
mod autoinstall;
pub use autoinstall::run as autoinstall;

#[cfg(feature = "selfupdate")]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved feature gates to module-level where possible

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;
Original file line number Diff line number Diff line change
@@ -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<bool>,
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) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<i64>,
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 {
Expand Down
Loading
Loading