diff --git a/src/bin/juliaup.rs b/src/bin/juliaup.rs index 74d3cd26..0626a369 100644 --- a/src/bin/juliaup.rs +++ b/src/bin/juliaup.rs @@ -1,5 +1,6 @@ use anyhow::{Context, Result}; use clap::Parser; +use juliaup::cli::{ConfigSubCmd, Juliaup, OverrideSubCmd, SelfSubCmd}; use juliaup::command_api::run_command_api; #[cfg(not(windows))] use juliaup::command_config_symlinks::run_command_config_symlinks; @@ -34,135 +35,6 @@ use juliaup::command_selfuninstall::run_command_selfuninstall_unavailable; use log::info; -#[derive(Parser)] -#[clap(name = "Juliaup", version)] -#[command( - after_help = "To launch a specific Julia version, use `julia +{channel}` e.g. `julia +1.6`. -Entering just `julia` uses the default channel set via `juliaup default`." -)] -/// The Julia Version Manager -enum Juliaup { - /// Set the default Julia version - Default { channel: String }, - /// Add a specific Julia version or channel to your system. Access via `julia +{channel}` e.g. `julia +1.6` - Add { channel: String }, - /// Link an existing Julia binary to a custom channel name - Link { - channel: String, - file: String, - args: Vec, - }, - /// List all available channels - #[clap(alias = "ls")] - List {}, - #[clap(subcommand, name = "override")] - OverrideSubCmd(OverrideSubCmd), - #[clap(alias = "up")] - /// Update all or a specific channel to the latest Julia version - Update { channel: Option }, - #[clap(alias = "rm")] - /// Remove a Julia version from your system - Remove { channel: String }, - #[clap(alias = "st")] - /// Show all installed Julia versions - Status {}, - /// Garbage collect uninstalled Julia versions - Gc {}, - #[clap(subcommand, name = "config")] - /// Juliaup configuration - Config(ConfigSubCmd), - #[clap(hide = true)] - Api { command: String }, - #[clap(name = "46029ef5-0b73-4a71-bff3-d0d05de42aac", hide = true)] - InitialSetupFromLauncher {}, - #[clap(name = "0cf1528f-0b15-46b1-9ac9-e5bf5ccccbcf", hide = true)] - UpdateVersionDb {}, - #[clap(name = "info", hide = true)] - Info {}, - #[clap(subcommand, name = "self")] - SelfSubCmd(SelfSubCmd), - // This is used for the cron jobs that we create. By using this UUID for the command - // We can identify the cron jobs that were created by juliaup for uninstall purposes - #[cfg(feature = "selfupdate")] - #[clap(name = "4c79c12db1d34bbbab1f6c6f838f423f", hide = true)] - SecretSelfUpdate {}, -} - -#[derive(Parser)] -/// Manage directory overrides -enum OverrideSubCmd { - Status {}, - Set { - channel: String, - #[clap(long, short)] - path: Option, - }, - Unset { - #[clap(long, short)] - nonexistent: bool, - #[clap(long, short)] - path: Option, - }, -} - -#[derive(Parser)] -/// Manage this juliaup installation -enum SelfSubCmd { - #[cfg(not(feature = "selfupdate"))] - /// Update the Julia versions database - Update {}, - #[cfg(feature = "selfupdate")] - /// Update the Julia versions database and juliaup itself - Update {}, - #[cfg(feature = "selfupdate")] - /// Configure the channel to use for juliaup updates - Channel { channel: String }, - #[cfg(feature = "selfupdate")] - /// Uninstall this version of juliaup from the system - Uninstall {}, - #[cfg(not(feature = "selfupdate"))] - /// Uninstall this version of juliaup from the system (UNAVAILABLE) - Uninstall {}, -} - -#[derive(Parser)] -enum ConfigSubCmd { - #[cfg(not(windows))] - #[clap(name = "channelsymlinks")] - /// Create a separate symlink per channel - ChannelSymlinks { - /// New Value - value: Option, - }, - #[cfg(feature = "selfupdate")] - #[clap(name = "backgroundselfupdateinterval")] - /// The time between automatic background updates of Juliaup in minutes, use 0 to disable. - BackgroundSelfupdateInterval { - /// New value - value: Option, - }, - #[cfg(feature = "selfupdate")] - #[clap(name = "startupselfupdateinterval")] - /// The time between automatic updates at Julia startup of Juliaup in minutes, use 0 to disable. - StartupSelfupdateInterval { - /// New value - value: Option, - }, - #[cfg(feature = "selfupdate")] - #[clap(name = "modifypath")] - /// Add the Julia binaries to your PATH by manipulating various shell startup scripts. - ModifyPath { - /// New value - value: Option, - }, - /// The time between automatic updates of the versions database in minutes, use 0 to disable. - #[clap(name = "versionsdbupdateinterval")] - VersionsDbUpdateInterval { - /// New value - value: Option, - }, -} - fn main() -> Result<()> { human_panic::setup_panic!(human_panic::Metadata { name: "Juliaup".into(), diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 00000000..5310eccd --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,130 @@ +use clap::Parser; + +#[derive(Parser)] +#[clap(name = "Juliaup", version)] +#[command( + after_help = "To launch a specific Julia version, use `julia +{channel}` e.g. `julia +1.6`. +Entering just `julia` uses the default channel set via `juliaup default`." +)] +/// The Julia Version Manager +pub enum Juliaup { + /// Set the default Julia version + Default { channel: String }, + /// Add a specific Julia version or channel to your system. Access via `julia +{channel}` e.g. `julia +1.6` + Add { channel: String }, + /// Link an existing Julia binary to a custom channel name + Link { + channel: String, + file: String, + args: Vec, + }, + /// List all available channels + #[clap(alias = "ls")] + List {}, + #[clap(subcommand, name = "override")] + OverrideSubCmd(OverrideSubCmd), + #[clap(alias = "up")] + /// Update all or a specific channel to the latest Julia version + Update { channel: Option }, + #[clap(alias = "rm")] + /// Remove a Julia version from your system + Remove { channel: String }, + #[clap(alias = "st")] + /// Show all installed Julia versions + Status {}, + /// Garbage collect uninstalled Julia versions + Gc {}, + #[clap(subcommand, name = "config")] + /// Juliaup configuration + Config(ConfigSubCmd), + #[clap(hide = true)] + Api { command: String }, + #[clap(name = "46029ef5-0b73-4a71-bff3-d0d05de42aac", hide = true)] + InitialSetupFromLauncher {}, + #[clap(name = "0cf1528f-0b15-46b1-9ac9-e5bf5ccccbcf", hide = true)] + UpdateVersionDb {}, + #[clap(name = "info", hide = true)] + Info {}, + #[clap(subcommand, name = "self")] + SelfSubCmd(SelfSubCmd), + // This is used for the cron jobs that we create. By using this UUID for the command + // We can identify the cron jobs that were created by juliaup for uninstall purposes + #[cfg(feature = "selfupdate")] + #[clap(name = "4c79c12db1d34bbbab1f6c6f838f423f", hide = true)] + SecretSelfUpdate {}, +} + +#[derive(Parser)] +/// Manage directory overrides +pub enum OverrideSubCmd { + Status {}, + Set { + channel: String, + #[clap(long, short)] + path: Option, + }, + Unset { + #[clap(long, short)] + nonexistent: bool, + #[clap(long, short)] + path: Option, + }, +} + +#[derive(Parser)] +/// Manage this juliaup installation +pub enum SelfSubCmd { + #[cfg(not(feature = "selfupdate"))] + /// Update the Julia versions database + Update {}, + #[cfg(feature = "selfupdate")] + /// Update the Julia versions database and juliaup itself + Update {}, + #[cfg(feature = "selfupdate")] + /// Configure the channel to use for juliaup updates + Channel { channel: String }, + #[cfg(feature = "selfupdate")] + /// Uninstall this version of juliaup from the system + Uninstall {}, + #[cfg(not(feature = "selfupdate"))] + /// Uninstall this version of juliaup from the system (UNAVAILABLE) + Uninstall {}, +} + +#[derive(Parser)] +pub enum ConfigSubCmd { + #[cfg(not(windows))] + #[clap(name = "channelsymlinks")] + /// Create a separate symlink per channel + ChannelSymlinks { + /// New Value + value: Option, + }, + #[cfg(feature = "selfupdate")] + #[clap(name = "backgroundselfupdateinterval")] + /// The time between automatic background updates of Juliaup in minutes, use 0 to disable. + BackgroundSelfupdateInterval { + /// New value + value: Option, + }, + #[cfg(feature = "selfupdate")] + #[clap(name = "startupselfupdateinterval")] + /// The time between automatic updates at Julia startup of Juliaup in minutes, use 0 to disable. + StartupSelfupdateInterval { + /// New value + value: Option, + }, + #[cfg(feature = "selfupdate")] + #[clap(name = "modifypath")] + /// Add the Julia binaries to your PATH by manipulating various shell startup scripts. + ModifyPath { + /// New value + value: Option, + }, + /// The time between automatic updates of the versions database in minutes, use 0 to disable. + #[clap(name = "versionsdbupdateinterval")] + VersionsDbUpdateInterval { + /// New value + value: Option, + }, +} diff --git a/src/lib.rs b/src/lib.rs index 7372acd4..6b5c2f72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ use anyhow::Context; +pub mod cli; pub mod command_add; pub mod command_api; pub mod command_config_backgroundselfupdate;