Skip to content

Commit

Permalink
refactor(command): update commands and cleanup on sync
Browse files Browse the repository at this point in the history
  • Loading branch information
QaidVoid committed Oct 10, 2024
1 parent 16e820a commit 555737c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 44 deletions.
52 changes: 23 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@ 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

- **Fast Installation**: Parallel package downloads and installations
- **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
Expand All @@ -31,28 +21,32 @@ cargo install --path .
## 🎯 Usage

```bash
soar fetch # Fetch and update metadata
soar install <package-names> # Install package(s)
soar search <package-name> # Search for a package
soar list # List installed packages
soar remove <package-names> # Remove package(s)
soar update [package-names] # Update package(s)
Usage: soar [OPTIONS] <COMMAND>

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

Expand Down
37 changes: 25 additions & 12 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -13,22 +14,25 @@ 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<String>,

/// Whether to force install the package
#[arg(required = false)]
#[arg(short, long)]
force: bool,
},

/// 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,
},
Expand All @@ -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<String>,
},

/// 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<Vec<String>>,
},

/// 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<Vec<String>>,
},

/// List all available packages
#[command(name = "list")]
#[clap(name = "list", alias = "ls")]
ListPackages {
/// Root path of packages
#[arg(required = false)]
root_path: Option<String>,
},

/// 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<String>,
},
Expand Down
6 changes: 5 additions & 1 deletion src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
40 changes: 40 additions & 0 deletions src/core/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,43 @@ pub async fn download(url: &str, what: &str) -> Result<Vec<u8>> {

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(())
}
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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?;
}
Expand Down

0 comments on commit 555737c

Please sign in to comment.