Skip to content

Commit

Permalink
Prepare 0.7.4 (#55)
Browse files Browse the repository at this point in the history
* deps upgrade

* feat: version 0.7.4

* make fmt and make clippy

* deps upgrade

* chore: linux fixes

* rebased main

* Updates changelog
  • Loading branch information
dilawar authored Oct 6, 2024
1 parent eeac20e commit 6936563
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.7.4] - 2024-10-07

- Adds `--install-default` option to `managers` command.
- Removes unneccessary use of `sudo` (#54).

## [0.7.3] - 2024-07-31

- Maintenance release.
Expand Down
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
[package]
name = "mpm"
version = "0.7.3"
version = "0.7.4"
edition = "2021"
license = "AGPL-3.0"

[dependencies]
anyhow = "1.0.86"
anyhow = "1.0.89"
clap = { version = "4.5", features = ["derive"] }
colored = "2.1"
sudo = "0.6"
xmltree = "0.10"
xmltree = "0.11"
os_info = "3.8.2"
strum = { version = "0.26", features = ["derive"] }
tabled = { version = "0.15", features = ["ansi"] }
tabled = { version = "0.16", features = ["ansi"] }
tracing = "0.1.40"
reqwest = { version = "0.12", features = ["blocking", "rustls-tls"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
ambassador = "0.4.1"
serde_json = "1.0.121"
serde = "1.0.204"
serde_json = "1.0.128"
serde = "1.0.210"
url = { version = "2.5.2", features = ["serde"] }
run-script-rs = { git = "https://github.com/SubconsciousCompute/run-script-rs", tag = "v0.2.1" }

[dev-dependencies]
tracing-test = "0.2.5"


59 changes: 49 additions & 10 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{Package, PackageManager};
#[command(
author,
version,
about = "A generic package manager.",
long_about = "A generic package manager for interfacing with multiple distro and platform specific package managers."
about = "A meta package manager.",
long_about = "A meta package manager for interfacing with multiple distro and platform specific package managers."
)]

/// Cli for PackageManager.
Expand All @@ -26,7 +26,7 @@ pub struct Cli {
manager: Option<crate::common::AvailablePackageManager>,

// TODO: See issue #33
// /// Set interactive mode
// Set interactive mode
// #[arg(long, short, default_value_t = false)]
// interactive: bool,
/// Set output to be in json format.
Expand All @@ -37,7 +37,12 @@ pub struct Cli {
#[derive(Subcommand)]
pub enum MpmPackageManagerCommands {
#[command(about = "List supported package managers and display their availability")]
Managers,
Managers {
/// Install default package manager if not found e.g. choco on Windows
/// and homebrew on osx.
#[arg(long, default_value_t = false)]
install_default: bool,
},

#[command(about = "Search for a given sub-string and list matching packages")]
Search { string: String },
Expand Down Expand Up @@ -95,19 +100,26 @@ pub fn execute(args: Cli) -> anyhow::Result<()> {
// elevate to root only for specific commands
let requires_sudo = matches!(
args.command,
MpmPackageManagerCommands::Install { .. } |
MpmPackageManagerCommands::Uninstall { .. } |
MpmPackageManagerCommands::Update { .. } |
MpmPackageManagerCommands::Repo { .. } |
MpmPackageManagerCommands::Sync
MpmPackageManagerCommands::Install { .. }
| MpmPackageManagerCommands::Uninstall { .. }
| MpmPackageManagerCommands::Update { .. }
| MpmPackageManagerCommands::Repo { .. }
| MpmPackageManagerCommands::Sync
);

if requires_sudo {
sudo();
}

match args.command {
MpmPackageManagerCommands::Managers => crate::print::print_managers(),
MpmPackageManagerCommands::Managers { install_default } => {
if install_default {
if let Err(e) = install_default_manager() {
eprintln!("Failed to install default package manager: {e}");
}
}
crate::print::print_managers();
}
MpmPackageManagerCommands::Search { string } => {
let pkgs = mpm.search(&string);
print_pkgs(&pkgs, args.json)?;
Expand Down Expand Up @@ -173,3 +185,30 @@ fn sudo() {
tracing::warn!("Failed to elevate to sudo: {e}.");
}
}

/// install default package manager.
#[cfg(windows)]
fn install_default_manager() -> anyhow::Result<()> {
println!("Installing choco package manager...");
let script = "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))";
let status = run_script_rs::run_script(script, false)?;
anyhow::ensure!(status.success(), "Command failed to install choco");
tracing::info!("{status:?}");
Ok(())
}

#[cfg(target_os = "macos")]
fn install_default_manager() -> anyhow::Result<()> {
println!("Installing homebrew on this system...");
let script = "curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh";
let status = run_script_rs::run_script(script, false)?;
anyhow::ensure!(status.success(), "Command failed to install homebrew");
tracing::info!("{status:?}");
Ok(())
}

#[cfg(target_os = "linux")]
fn install_default_manager() -> anyhow::Result<()> {
println!("This command does nothing on linux.");
Ok(())
}
2 changes: 1 addition & 1 deletion src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Listing {
/// information
pub fn print_managers() {
notify!(
"a total of {} package managers are supported",
"Total {} package managers are supported",
AvailablePackageManager::COUNT
);
let table = Table::new(AvailablePackageManager::iter().map(Listing::new));
Expand Down

0 comments on commit 6936563

Please sign in to comment.