mirror of
https://github.com/eRgo35/ah.git
synced 2026-02-04 13:16:11 +01:00
Compare commits
5 Commits
d40da30a50
...
f2f3997469
| Author | SHA1 | Date | |
|---|---|---|---|
|
f2f3997469
|
|||
|
d3d1b38f7e
|
|||
|
610f94d1d4
|
|||
|
b11271cf82
|
|||
|
0d0c544088
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
|
*.tar.zst
|
||||||
|
/pkg
|
||||||
103
Cargo.lock
generated
103
Cargo.lock
generated
@@ -7,6 +7,7 @@ name = "ah"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
|
"colored",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -45,7 +46,7 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391"
|
checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -55,7 +56,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
|
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"windows-sys",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -104,6 +105,16 @@ version = "1.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
|
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colored"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -116,6 +127,12 @@ version = "1.70.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.86"
|
version = "1.0.86"
|
||||||
@@ -163,13 +180,37 @@ version = "0.2.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.52.0"
|
version = "0.52.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-targets",
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm 0.48.5",
|
||||||
|
"windows_aarch64_msvc 0.48.5",
|
||||||
|
"windows_i686_gnu 0.48.5",
|
||||||
|
"windows_i686_msvc 0.48.5",
|
||||||
|
"windows_x86_64_gnu 0.48.5",
|
||||||
|
"windows_x86_64_gnullvm 0.48.5",
|
||||||
|
"windows_x86_64_msvc 0.48.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -178,28 +219,46 @@ version = "0.52.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows_aarch64_gnullvm",
|
"windows_aarch64_gnullvm 0.52.6",
|
||||||
"windows_aarch64_msvc",
|
"windows_aarch64_msvc 0.52.6",
|
||||||
"windows_i686_gnu",
|
"windows_i686_gnu 0.52.6",
|
||||||
"windows_i686_gnullvm",
|
"windows_i686_gnullvm",
|
||||||
"windows_i686_msvc",
|
"windows_i686_msvc 0.52.6",
|
||||||
"windows_x86_64_gnu",
|
"windows_x86_64_gnu 0.52.6",
|
||||||
"windows_x86_64_gnullvm",
|
"windows_x86_64_gnullvm 0.52.6",
|
||||||
"windows_x86_64_msvc",
|
"windows_x86_64_msvc 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_gnullvm"
|
name = "windows_aarch64_gnullvm"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_msvc"
|
name = "windows_aarch64_msvc"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_gnu"
|
name = "windows_i686_gnu"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -212,24 +271,48 @@ version = "0.52.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_msvc"
|
name = "windows_i686_msvc"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnu"
|
name = "windows_x86_64_gnu"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnullvm"
|
name = "windows_x86_64_gnullvm"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_msvc"
|
name = "windows_x86_64_msvc"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
|
|||||||
10
Cargo.toml
10
Cargo.toml
@@ -1,7 +1,17 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ah"
|
name = "ah"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
authors = ["Michał Czyż <mike@c2yz.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
description = "A declarative package manager for Arch Linux"
|
||||||
|
homepage = "https://github.com/eRgo35/ah"
|
||||||
|
repository = "https://github.com/eRgo35/ah"
|
||||||
|
documentation = "https://github.com/eRgo35/ah"
|
||||||
|
license = "MIT"
|
||||||
|
keywords = ["archlinux", "declarative", "package", "aur", "paru"]
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.10", features = ["derive"] }
|
clap = { version = "4.5.10", features = ["derive"] }
|
||||||
|
colored = "2.1.0"
|
||||||
25
PKGBUILD
Normal file
25
PKGBUILD
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Maintainer: Michał Czyż <mike@c2yz.com>
|
||||||
|
pkgname=ah
|
||||||
|
pkgver=0.1.0
|
||||||
|
pkgrel=1
|
||||||
|
pkgdesc="A declarative package manager for Arch Linux"
|
||||||
|
url="https://github.com/eRgo35/ah"
|
||||||
|
license=("MIT")
|
||||||
|
arch=("x86_64")
|
||||||
|
makedepends=("cargo")
|
||||||
|
|
||||||
|
pkgver() {
|
||||||
|
(git describe --long --tags || echo "$pkgver") | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
cd ..
|
||||||
|
usrdir="$pkgdir/usr"
|
||||||
|
mkdir -p $usrdir
|
||||||
|
cargo install --no-track --path . --root "$usrdir"
|
||||||
|
}
|
||||||
|
|
||||||
58
README.md
58
README.md
@@ -1,9 +1,63 @@
|
|||||||
# ah
|
# ah
|
||||||
|
|
||||||
Yet another AUR helper
|
A declarative package manager for Arch Linux
|
||||||
|
|
||||||
## What is ah?
|
## What is ah?
|
||||||
|
|
||||||
AH is a wrapper for paru that allows for declarative management of packages on your system.
|
Arch Helper is a declarative package management tool for Arch Linux. It leverages paru or other package managers for seamless integration.
|
||||||
|
|
||||||
It is currently in early development phase so watch out for bugs!
|
It is currently in early development phase so watch out for bugs!
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Install Rust :crab:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ sudo pacman -S rustup
|
||||||
|
```
|
||||||
|
|
||||||
|
Initialize default stable
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ rustup default stable
|
||||||
|
```
|
||||||
|
|
||||||
|
Clone this repo
|
||||||
|
```sh
|
||||||
|
$ git clone https://github.com/eRgo35/ah
|
||||||
|
```
|
||||||
|
Change directory
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ cd ah
|
||||||
|
```
|
||||||
|
|
||||||
|
Install package
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ makepkg -si
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```txt
|
||||||
|
$ ah --help
|
||||||
|
Arch Helper is a declarative package management tool for Arch Linux. It leverages paru or other package managers for seamless integration.
|
||||||
|
|
||||||
|
Usage: ah [COMMAND]
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
install Install packages
|
||||||
|
upgrade Upgrade packages
|
||||||
|
sync Synchronize packages
|
||||||
|
remove Remove packages
|
||||||
|
find Find packages
|
||||||
|
help Print this message or the help of the given subcommand(s)
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help
|
||||||
|
Print help (see a summary with '-h')
|
||||||
|
|
||||||
|
-V, --version
|
||||||
|
Print version
|
||||||
|
```
|
||||||
|
|||||||
50
src/cli.rs
Normal file
50
src/cli.rs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
use clap::{Args, Parser, Subcommand};
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[command(
|
||||||
|
name = "ah",
|
||||||
|
author = "Michał Czyż",
|
||||||
|
version = "0.1.0",
|
||||||
|
about = "A declarative package manager for Arch Linux",
|
||||||
|
long_about = "Arch Helper is a declarative package management tool for Arch Linux. It leverages paru or other package managers for seamless integration."
|
||||||
|
)]
|
||||||
|
pub struct Cli {
|
||||||
|
#[command(subcommand)]
|
||||||
|
pub command: Option<Commands>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
pub enum Commands {
|
||||||
|
#[command(alias = "i", about = "Install packages")]
|
||||||
|
Install(PackageList),
|
||||||
|
|
||||||
|
#[command(alias = "u", about = "Upgrade packages")]
|
||||||
|
Upgrade {
|
||||||
|
#[arg(help = "Don't prompt for confirmation", default_value_t = false)]
|
||||||
|
noconfirm: bool,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[command(alias = "s", about = "Synchronize packages")]
|
||||||
|
Sync {
|
||||||
|
#[arg(help = "Don't prompt for confirmation", default_value_t = false)]
|
||||||
|
noconfirm: bool,
|
||||||
|
},
|
||||||
|
|
||||||
|
#[command(alias = "r", about = "Remove packages")]
|
||||||
|
Remove(PackageList),
|
||||||
|
|
||||||
|
#[command(alias = "f", about = "Find packages")]
|
||||||
|
Find(Query),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
pub struct PackageList {
|
||||||
|
#[arg(help = "Name(s) of the package(s), separated by spaces")]
|
||||||
|
pub packages: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
pub struct Query {
|
||||||
|
#[arg(help = "Search term for finding packages")]
|
||||||
|
pub query: Vec<String>,
|
||||||
|
}
|
||||||
46
src/file.rs
Normal file
46
src/file.rs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
use std::{
|
||||||
|
fs::{File, OpenOptions},
|
||||||
|
io::{prelude::*, BufReader},
|
||||||
|
path::PathBuf,
|
||||||
|
};
|
||||||
|
|
||||||
|
// pub fn read_config(path: &str) -> Vec<String> {
|
||||||
|
// todo!();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// pub fn write_config(path: &str, content: &str) {
|
||||||
|
// todo!();
|
||||||
|
// }
|
||||||
|
|
||||||
|
pub fn read_packages(path: PathBuf) -> Vec<String> {
|
||||||
|
let file = File::open(path).expect("Failed to open file");
|
||||||
|
let buf = BufReader::new(file);
|
||||||
|
|
||||||
|
buf.lines()
|
||||||
|
.map(|l| l.expect("Failed to read line"))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn append_package(path: PathBuf, package: &str) {
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.append(true)
|
||||||
|
.open(path)
|
||||||
|
.expect("Failed to open file");
|
||||||
|
|
||||||
|
if let Err(err) = writeln!(file, "{}", package) {
|
||||||
|
eprintln!("Couldn't write to file: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_packages(path: PathBuf, content: &str) {
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(path)
|
||||||
|
.expect("Failed to open file");
|
||||||
|
|
||||||
|
if let Err(err) = writeln!(file, "{}", content) {
|
||||||
|
eprintln!("Couldn't write to file: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
53
src/main.rs
53
src/main.rs
@@ -1,40 +1,25 @@
|
|||||||
use clap::{Command, Parser, Subcommand, Args};
|
use clap::Parser;
|
||||||
|
use cli::{PackageList, Query};
|
||||||
|
use colored::Colorize;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
mod cli;
|
||||||
#[command(version, about, long_about = None)]
|
mod file;
|
||||||
struct Cli {
|
mod packages;
|
||||||
#[command(subcommand)]
|
|
||||||
pub command: Option<SubCommands>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
|
||||||
enum SubCommands {
|
|
||||||
#[command(alias = "i")]
|
|
||||||
Install(PackageArg),
|
|
||||||
#[command(alias = "u")]
|
|
||||||
Upgrade {},
|
|
||||||
#[command(alias = "s")]
|
|
||||||
Sync {},
|
|
||||||
#[command(alias = "r")]
|
|
||||||
Remove(PackageArg),
|
|
||||||
#[command(alias = "f")]
|
|
||||||
Find(PackageArg),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Args, Debug)]
|
|
||||||
struct PackageArg {
|
|
||||||
package: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = cli::Cli::parse();
|
||||||
|
|
||||||
match cli.command {
|
let result = match cli.command {
|
||||||
Some(SubCommands::Install(arg)) => println!("Installing package: {}", arg.package),
|
Some(cli::Commands::Install(PackageList { packages })) => packages::install(packages),
|
||||||
Some(SubCommands::Upgrade {}) => todo!(),
|
Some(cli::Commands::Upgrade { noconfirm }) => packages::upgrade(noconfirm),
|
||||||
Some(SubCommands::Sync {}) => todo!(),
|
Some(cli::Commands::Sync { noconfirm }) => packages::sync(noconfirm),
|
||||||
Some(SubCommands::Remove(arg)) => println!("Removing package: {}", arg.package),
|
Some(cli::Commands::Remove(PackageList { packages })) => packages::remove(packages),
|
||||||
Some(SubCommands::Find(arg)) => println!("Looking for package: {}", arg.package),
|
Some(cli::Commands::Find(Query { query })) => packages::find(query),
|
||||||
None => println!("No subcommand was used"),
|
None => packages::rebuild(true),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(err) = result {
|
||||||
|
eprintln!("{} {}", "::".bold().red(), err.to_string().bold());
|
||||||
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
src/packages/find.rs
Normal file
28
src/packages/find.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
use colored::Colorize;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
|
|
||||||
|
pub fn find(query: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().green(),
|
||||||
|
"Looking for package...".bold()
|
||||||
|
);
|
||||||
|
|
||||||
|
if query.is_empty() {
|
||||||
|
return Err("No query provided".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = Command::new(PACKAGE_MANAGER)
|
||||||
|
.arg("--color")
|
||||||
|
.arg("always")
|
||||||
|
.arg("-Ss")
|
||||||
|
.args(query)
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
print!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
62
src/packages/install.rs
Normal file
62
src/packages/install.rs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
use crate::{file, packages::get_package_path};
|
||||||
|
use colored::Colorize;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
|
|
||||||
|
pub fn install(new_packages: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().green(),
|
||||||
|
"Installing packages...".bold()
|
||||||
|
);
|
||||||
|
|
||||||
|
let packages = file::read_packages(get_package_path());
|
||||||
|
|
||||||
|
let packages = packages
|
||||||
|
.into_iter()
|
||||||
|
.filter(|p| !p.contains("#") && !p.is_empty())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let mut child = Command::new(PACKAGE_MANAGER)
|
||||||
|
.arg("--color")
|
||||||
|
.arg("always")
|
||||||
|
.arg("-S")
|
||||||
|
.arg("--needed")
|
||||||
|
// .arg(noconfirm)
|
||||||
|
.arg("-")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
if let Some(mut stdin) = child.stdin.take() {
|
||||||
|
for new_package in new_packages.clone() {
|
||||||
|
writeln!(stdin, "{}", new_package).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let status = child.wait().expect("Failed to wait on child");
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
return Err("Failed to install packages".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{} {}", "::".bold().green(), "Packages installed".bold());
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().blue(),
|
||||||
|
"Updating package index...".bold()
|
||||||
|
);
|
||||||
|
|
||||||
|
for new_package in new_packages {
|
||||||
|
if !packages.contains(&new_package) {
|
||||||
|
file::append_package(get_package_path(), &new_package);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
38
src/packages/mod.rs
Normal file
38
src/packages/mod.rs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
use colored::Colorize;
|
||||||
|
use std::io::{self, Write};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub mod find;
|
||||||
|
pub mod install;
|
||||||
|
pub mod rebuild;
|
||||||
|
pub mod remove;
|
||||||
|
pub mod sync;
|
||||||
|
pub mod upgrade;
|
||||||
|
|
||||||
|
pub use find::find;
|
||||||
|
pub use install::install;
|
||||||
|
pub use rebuild::rebuild;
|
||||||
|
pub use remove::remove;
|
||||||
|
pub use sync::sync;
|
||||||
|
pub use upgrade::upgrade;
|
||||||
|
|
||||||
|
fn get_package_path() -> PathBuf {
|
||||||
|
let home_dir = std::env::var("HOME").unwrap();
|
||||||
|
|
||||||
|
PathBuf::from(home_dir).join("packages")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ask_confirmation() -> Result<bool, io::Error> {
|
||||||
|
print!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().blue(),
|
||||||
|
"Do you want to continue? [Y/n] "
|
||||||
|
);
|
||||||
|
io::stdout().flush()?;
|
||||||
|
|
||||||
|
let mut input = String::new();
|
||||||
|
io::stdin().read_line(&mut input)?;
|
||||||
|
|
||||||
|
let input = input.trim().to_lowercase();
|
||||||
|
Ok(input.is_empty() || input == "y")
|
||||||
|
}
|
||||||
65
src/packages/rebuild.rs
Normal file
65
src/packages/rebuild.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
use colored::Colorize;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
use crate::file;
|
||||||
|
use crate::packages::{ask_confirmation, get_package_path};
|
||||||
|
|
||||||
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
|
|
||||||
|
pub fn rebuild(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().green(),
|
||||||
|
"Upgrading & syncing packages...".bold()
|
||||||
|
);
|
||||||
|
|
||||||
|
if !ask_confirmation()? {
|
||||||
|
return Err("Operation aborted".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let packages = file::read_packages(get_package_path());
|
||||||
|
|
||||||
|
let packages = packages
|
||||||
|
.into_iter()
|
||||||
|
.filter(|p| !p.contains("#") && !p.is_empty())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let noconfirm = if noconfirm {
|
||||||
|
"--noconfirm"
|
||||||
|
} else {
|
||||||
|
"--confirm"
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut child = Command::new(PACKAGE_MANAGER)
|
||||||
|
.arg("--color")
|
||||||
|
.arg("always")
|
||||||
|
.arg("-Syu")
|
||||||
|
.arg("--needed")
|
||||||
|
.arg(noconfirm)
|
||||||
|
.arg("-")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
if let Some(mut stdin) = child.stdin.take() {
|
||||||
|
for package in packages {
|
||||||
|
writeln!(stdin, "{}", package).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let status = child.wait().expect("Failed to wait on child");
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
return Err("Failed to upgrade & sync packages".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().green(),
|
||||||
|
"Packages upgraded & synced".bold()
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
58
src/packages/remove.rs
Normal file
58
src/packages/remove.rs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
use crate::{file, packages::get_package_path};
|
||||||
|
use colored::Colorize;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
|
|
||||||
|
pub fn remove(unwanted_packages: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("{} {}", "::".bold().green(), "Removing packages...".bold());
|
||||||
|
|
||||||
|
let packages = file::read_packages(get_package_path());
|
||||||
|
|
||||||
|
let mut packages = packages
|
||||||
|
.into_iter()
|
||||||
|
.filter(|p| !p.contains("#") && !p.is_empty())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let mut child = Command::new(PACKAGE_MANAGER)
|
||||||
|
.arg("--color")
|
||||||
|
.arg("always")
|
||||||
|
.arg("-R")
|
||||||
|
// .arg("--needed")
|
||||||
|
// .arg(noconfirm)
|
||||||
|
.arg("-")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
if let Some(mut stdin) = child.stdin.take() {
|
||||||
|
for unwanted_package in unwanted_packages.clone() {
|
||||||
|
writeln!(stdin, "{}", unwanted_package).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let status = child.wait().expect("Failed to wait on child");
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
return Err("Failed to remove packages".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{} {}", "::".bold().green(), "Packages removed".bold());
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
"::".bold().blue(),
|
||||||
|
"Updating package index...".bold()
|
||||||
|
);
|
||||||
|
|
||||||
|
for unwanted_package in unwanted_packages {
|
||||||
|
packages.retain(|p| *p != unwanted_package);
|
||||||
|
}
|
||||||
|
|
||||||
|
file::write_packages(get_package_path(), &packages.join("\n"));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
57
src/packages/sync.rs
Normal file
57
src/packages/sync.rs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
use colored::Colorize;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
use crate::file;
|
||||||
|
use crate::packages::{ask_confirmation, get_package_path};
|
||||||
|
|
||||||
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
|
|
||||||
|
pub fn sync(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("{} {}", "::".bold().green(), "Syncing packages...".bold());
|
||||||
|
|
||||||
|
if !ask_confirmation()? {
|
||||||
|
return Err("Operation aborted".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let packages = file::read_packages(get_package_path());
|
||||||
|
|
||||||
|
let packages = packages
|
||||||
|
.into_iter()
|
||||||
|
.filter(|p| !p.contains("#") && !p.is_empty())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let noconfirm = if noconfirm {
|
||||||
|
"--noconfirm"
|
||||||
|
} else {
|
||||||
|
"--confirm"
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut child = Command::new(PACKAGE_MANAGER)
|
||||||
|
.arg("--color")
|
||||||
|
.arg("always")
|
||||||
|
.arg("-S")
|
||||||
|
.arg("--needed")
|
||||||
|
.arg(noconfirm)
|
||||||
|
.arg("-")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
if let Some(mut stdin) = child.stdin.take() {
|
||||||
|
for package in packages {
|
||||||
|
writeln!(stdin, "{}", package).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let status = child.wait().expect("Failed to wait on child");
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
return Err("Failed to sync packages".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{} {}", "::".bold().green(), "Packages synced".bold());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
37
src/packages/upgrade.rs
Normal file
37
src/packages/upgrade.rs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
use colored::Colorize;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
use crate::packages::ask_confirmation;
|
||||||
|
|
||||||
|
const PACKAGE_MANAGER: &str = "paru";
|
||||||
|
|
||||||
|
pub fn upgrade(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("{} {}", "::".bold().green(), "Upgrading packages...".bold());
|
||||||
|
|
||||||
|
if !ask_confirmation()? {
|
||||||
|
return Err("Operation aborted".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let noconfirm = if noconfirm {
|
||||||
|
"--noconfirm"
|
||||||
|
} else {
|
||||||
|
"--confirm"
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut child = Command::new(PACKAGE_MANAGER)
|
||||||
|
.arg("--color")
|
||||||
|
.arg("always")
|
||||||
|
.arg("-Syu")
|
||||||
|
.arg(noconfirm)
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
let status = child.wait().expect("Failed to wait on child");
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
return Err("Failed to upgrade packages".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{} {}", "::".bold().green(), "Packages upgraded".bold());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user