diff --git a/README.md b/README.md index 2437278..cba970d 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,7 @@ A fast, modern package manager for Linux systems. [![Under Development](https://img.shields.io/badge/status-under%20development-orange)](https://github.com/QaidVoid/soar) -> **Note**: Soar is currently under rapid development. The codebase is being -actively refactored and improved. New features will be added after a -comprehensive restructuring of the core components. +> **Note**: Soar is currently under rapid development. ## 🌟 Features @@ -14,14 +12,6 @@ comprehensive restructuring of the core components. - **Package Management**: Install, remove, update, and list packages effortlessly - **Repository Support**: Multiple repository configurations -## 🚀 Current Capabilities - -- `install` - Install packages from configured repositories -- `search` - Search for available packages -- `list` - List installed packages -- `remove` - Remove installed packages -- `update` - Update installed packages (currently using install methods internally) - ## 🔧 Installation ```bash @@ -31,28 +21,32 @@ cargo install --path . ## 🎯 Usage ```bash -soar fetch # Fetch and update metadata -soar install # Install package(s) -soar search # Search for a package -soar list # List installed packages -soar remove # Remove package(s) -soar update [package-names] # Update package(s) +Usage: soar [OPTIONS] + +Commands: + install Install packages; supports '--force' flag [aliases: i] + search Search package [aliases: s] + query Query package info [aliases: Q] + remove Remove packages [aliases: r] + sync Sync with remote registry [aliases: S] + update Update packages [aliases: u] + info Show info about installed packages + list List all available packages + inspect Inspect package build log + run Run packages without installing to PATH [aliases: exec] + help Print this message or the help of the given subcommand(s) + +Options: + -v, --verbose Unimplemented + -h, --help Print help + -V, --version Print version ``` -## 🚧 Development Status - -Soar is currently in active development. - -- The codebase is undergoing significant refactoring -- Some features (like update) don't work as expected -- New features are planned post-refactoring - ## 🤝 Contributing -Currently, contributions are not accepted as the project is undergoing a heavy -refactor. Interest is appreciated, and contributions will be welcomed once the -refactoring is complete. Suggestions and feedback will be invaluable at that -time! +We welcome contributions! Please feel free to fork the repository and submit +pull requests. If you have suggestions or feature requests, open an issue to +discuss. ## 📝 License diff --git a/src/cli.rs b/src/cli.rs index fcd4920..3843a51 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -4,6 +4,7 @@ use clap::{Parser, Subcommand}; #[command(author, version)] #[command(arg_required_else_help = true)] pub struct Args { + /// Unimplemented #[arg(short, long)] pub verbose: bool, @@ -13,13 +14,15 @@ pub struct Args { #[derive(Subcommand)] pub enum Commands { - /// Install packages + /// Install packages; supports '--force' flag #[command(arg_required_else_help = true)] - #[clap(name = "install", visible_alias = "i")] + #[clap(name = "install", visible_alias = "i", alias = "add")] Install { + /// Packages to install #[arg(required = true)] packages: Vec, + /// Whether to force install the package #[arg(required = false)] #[arg(short, long)] force: bool, @@ -27,8 +30,9 @@ pub enum Commands { /// Search package #[command(arg_required_else_help = true)] - #[clap(name = "search", visible_alias = "s")] + #[clap(name = "search", visible_alias = "s", alias = "find")] Search { + /// Query to search #[arg(required = true)] query: String, }, @@ -37,53 +41,62 @@ pub enum Commands { #[command(arg_required_else_help = true)] #[clap(name = "query", visible_alias = "Q")] Query { + /// Package to inspect #[arg(required = true)] query: String, }, /// Remove packages #[command(arg_required_else_help = true)] - #[clap(name = "remove", visible_alias = "r")] + #[clap(name = "remove", visible_alias = "r", alias = "del")] Remove { + /// Packages to remove #[arg(required = true)] packages: Vec, }, - /// Fetch and update metadata - #[command(name = "fetch")] - Fetch, + /// Sync with remote registry + #[clap(name = "sync", visible_alias = "S", alias = "fetch")] + Sync, /// Update packages - #[command(name = "update", visible_alias = "u")] + #[clap(name = "update", visible_alias = "u", alias = "upgrade")] Update { + /// Packages to update #[arg(required = false)] packages: Option>, }, /// Show info about installed packages - #[command(name = "info")] + #[clap(name = "info", alias = "list-installed")] ListInstalledPackages { + /// Packages to get info about #[arg(required = false)] packages: Option>, }, /// List all available packages - #[command(name = "list")] + #[clap(name = "list", alias = "ls")] ListPackages { + /// Root path of packages #[arg(required = false)] root_path: Option, }, /// Inspect package build log - #[command(name = "inspect")] + #[command(arg_required_else_help = true)] + #[clap(name = "inspect", alias = "log")] Inspect { + /// Package to inspect #[arg(required = true)] package: String, }, /// Run packages without installing to PATH - #[command(name = "run")] + #[command(arg_required_else_help = true)] + #[clap(name = "run", visible_alias = "exec", alias = "execute")] Run { + /// Command to execute #[arg(required = true)] command: Vec, }, diff --git a/src/core/config.rs b/src/core/config.rs index 1af2138..da6139b 100644 --- a/src/core/config.rs +++ b/src/core/config.rs @@ -55,7 +55,11 @@ impl Config { let content = match fs::read(&config_path) { Ok(content) => content, Err(e) if e.kind() == std::io::ErrorKind::NotFound => { - fs::create_dir_all(pkg_config).unwrap(); + fs::create_dir_all(&pkg_config).unwrap(); + eprintln!( + "Config not found. Generating default config at {}", + config_path.to_string_lossy() + ); Config::generate(config_path) } Err(e) => { diff --git a/src/core/util.rs b/src/core/util.rs index 8590377..2e66fa7 100644 --- a/src/core/util.rs +++ b/src/core/util.rs @@ -158,3 +158,43 @@ pub async fn download(url: &str, what: &str) -> Result> { Ok(content) } + +pub async fn cleanup() -> Result<()> { + let mut cache_dir = env::var("XDG_CACHE_HOME").unwrap_or_else(|_| { + env::var("HOME").map_or_else( + |_| panic!("Failed to retrieve HOME environment variable"), + |home| format!("{}/.cache", home), + ) + }); + cache_dir.push_str("/soar"); + let cache_dir = build_path(&cache_dir)?; + + if cache_dir.exists() { + let mut tree = fs::read_dir(&cache_dir).await?; + + while let Some(entry) = tree.next_entry().await? { + let path = entry.path(); + if xattr::get(&path, "user.ManagedBy")?.as_deref() != Some(b"soar") { + continue; + }; + + fs::remove_file(path).await?; + } + } + + remove_broken_symlink().await?; + + Ok(()) +} + +pub async fn remove_broken_symlink() -> Result<()> { + let mut tree = fs::read_dir(&*BIN_PATH).await?; + while let Some(entry) = tree.next_entry().await? { + let path = entry.path(); + if !path.is_file() { + fs::remove_file(path).await?; + } + } + + Ok(()) +} diff --git a/src/lib.rs b/src/lib.rs index a732d8d..5142cf0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,10 @@ use clap::Parser; use cli::{Args, Commands}; use registry::PackageRegistry; -use core::{config, util::setup_required_paths}; +use core::{ + config, + util::{cleanup, setup_required_paths}, +}; mod cli; mod core; @@ -19,7 +22,8 @@ pub async fn init() -> Result<()> { Commands::Install { packages, force } => { registry.install_packages(&packages, force, false).await?; } - Commands::Fetch => { + Commands::Sync => { + cleanup().await?; let mut registry = registry; registry.fetch().await?; }