Compare commits

11 Commits

18 changed files with 492 additions and 80 deletions

281
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,281 @@
# Copyright 2022-2024, axodotdev
# SPDX-License-Identifier: MIT or Apache-2.0
#
# CI that:
#
# * checks for a Git Tag that looks like a release
# * builds artifacts with cargo-dist (archives, installers, hashes)
# * uploads those artifacts to temporary workflow zip
# * on success, uploads the artifacts to a GitHub Release
#
# Note that the GitHub Release will be created with a generated
# title/body based on your changelogs.
name: Release
permissions:
"contents": "write"
# This task will run whenever you push a git tag that looks like a version
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
#
# If PACKAGE_NAME is specified, then the announcement will be for that
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
#
# If PACKAGE_NAME isn't specified, then the announcement will be for all
# (cargo-dist-able) packages in the workspace with that version (this mode is
# intended for workspaces with only one dist-able package, or with all dist-able
# packages versioned/released in lockstep).
#
# If you push multiple tags at once, separate instances of this workflow will
# spin up, creating an independent announcement for each one. However, GitHub
# will hard limit this to 3 tags per commit, as it will assume more tags is a
# mistake.
#
# If there's a prerelease-style suffix to the version, then the release(s)
# will be marked as a prerelease.
on:
pull_request:
push:
tags:
- '**[0-9]+.[0-9]+.[0-9]+*'
jobs:
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
plan:
runs-on: "ubuntu-20.04"
outputs:
val: ${{ steps.plan.outputs.manifest }}
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
publishing: ${{ !github.event.pull_request }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install cargo-dist
# we specify bash to get pipefail; it guards against the `curl` command
# failing. otherwise `sh` won't catch that `curl` returned non-0
shell: bash
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.20.0/cargo-dist-installer.sh | sh"
- name: Cache cargo-dist
uses: actions/upload-artifact@v4
with:
name: cargo-dist-cache
path: ~/.cargo/bin/cargo-dist
# sure would be cool if github gave us proper conditionals...
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
# functionality based on whether this is a pull_request, and whether it's from a fork.
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
# but also really annoying to build CI around when it needs secrets to work right.)
- id: plan
run: |
cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
echo "cargo dist ran successfully"
cat plan-dist-manifest.json
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
- name: "Upload dist-manifest.json"
uses: actions/upload-artifact@v4
with:
name: artifacts-plan-dist-manifest
path: plan-dist-manifest.json
# Build and packages all the platform-specific things
build-local-artifacts:
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
# Let the initial task tell us to not run (currently very blunt)
needs:
- plan
if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
strategy:
fail-fast: false
# Target platforms/runners are computed by cargo-dist in create-release.
# Each member of the matrix has the following arguments:
#
# - runner: the github runner
# - dist-args: cli flags to pass to cargo dist
# - install-dist: expression to run to install cargo-dist on the runner
#
# Typically there will be:
# - 1 "global" task that builds universal installers
# - N "local" tasks that build each platform's binaries and platform-specific installers
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
runs-on: ${{ matrix.runner }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
steps:
- name: enable windows longpaths
run: |
git config --global core.longpaths true
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install cargo-dist
run: ${{ matrix.install_dist }}
# Get the dist-manifest
- name: Fetch local artifacts
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: target/distrib/
merge-multiple: true
- name: Install dependencies
run: |
${{ matrix.packages_install }}
- name: Build artifacts
run: |
# Actually do builds and make zips and whatnot
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
echo "cargo dist ran successfully"
- id: cargo-dist
name: Post-build
# We force bash here just because github makes it really hard to get values up
# to "real" actions without writing to env-vars, and writing to env-vars has
# inconsistent syntax between shell and powershell.
shell: bash
run: |
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
- name: "Upload artifacts"
uses: actions/upload-artifact@v4
with:
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
path: |
${{ steps.cargo-dist.outputs.paths }}
${{ env.BUILD_MANIFEST_NAME }}
# Build and package all the platform-agnostic(ish) things
build-global-artifacts:
needs:
- plan
- build-local-artifacts
runs-on: "ubuntu-20.04"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install cached cargo-dist
uses: actions/download-artifact@v4
with:
name: cargo-dist-cache
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/cargo-dist
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
- name: Fetch local artifacts
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: target/distrib/
merge-multiple: true
- id: cargo-dist
shell: bash
run: |
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
echo "cargo dist ran successfully"
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
- name: "Upload artifacts"
uses: actions/upload-artifact@v4
with:
name: artifacts-build-global
path: |
${{ steps.cargo-dist.outputs.paths }}
${{ env.BUILD_MANIFEST_NAME }}
# Determines if we should publish/announce
host:
needs:
- plan
- build-local-artifacts
- build-global-artifacts
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
if: ${{ always() && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
runs-on: "ubuntu-20.04"
outputs:
val: ${{ steps.host.outputs.manifest }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install cached cargo-dist
uses: actions/download-artifact@v4
with:
name: cargo-dist-cache
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/cargo-dist
# Fetch artifacts from scratch-storage
- name: Fetch artifacts
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: target/distrib/
merge-multiple: true
- id: host
shell: bash
run: |
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
echo "artifacts uploaded and released successfully"
cat dist-manifest.json
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
- name: "Upload dist-manifest.json"
uses: actions/upload-artifact@v4
with:
# Overwrite the previous copy
name: artifacts-dist-manifest
path: dist-manifest.json
# Create a GitHub Release while uploading all files to it
- name: "Download GitHub Artifacts"
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: artifacts
merge-multiple: true
- name: Cleanup
run: |
# Remove the granular manifests
rm -f artifacts/*-dist-manifest.json
- name: Create GitHub Release
env:
PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
RELEASE_COMMIT: "${{ github.sha }}"
run: |
# Write and read notes from a file to avoid quoting breaking things
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
announce:
needs:
- plan
- host
# use "always() && ..." to allow us to wait for all publish jobs while
# still allowing individual publish jobs to skip themselves (for prereleases).
# "host" however must run to completion, no skipping allowed!
if: ${{ always() && needs.host.result == 'success' }}
runs-on: "ubuntu-20.04"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

52
Cargo.lock generated
View File

@@ -3,8 +3,8 @@
version = 3 version = 3
[[package]] [[package]]
name = "ah" name = "ah-pkg"
version = "0.1.0" version = "0.3.1"
dependencies = [ dependencies = [
"clap", "clap",
"colored", "colored",
@@ -12,9 +12,9 @@ dependencies = [
[[package]] [[package]]
name = "anstream" name = "anstream"
version = "0.6.14" version = "0.6.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
dependencies = [ dependencies = [
"anstyle", "anstyle",
"anstyle-parse", "anstyle-parse",
@@ -27,33 +27,33 @@ dependencies = [
[[package]] [[package]]
name = "anstyle" name = "anstyle"
version = "1.0.7" version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
[[package]] [[package]]
name = "anstyle-parse" name = "anstyle-parse"
version = "0.2.4" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
dependencies = [ dependencies = [
"utf8parse", "utf8parse",
] ]
[[package]] [[package]]
name = "anstyle-query" name = "anstyle-query"
version = "1.1.0" version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
dependencies = [ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]] [[package]]
name = "anstyle-wincon" name = "anstyle-wincon"
version = "3.0.3" version = "3.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
dependencies = [ dependencies = [
"anstyle", "anstyle",
"windows-sys 0.52.0", "windows-sys 0.52.0",
@@ -61,9 +61,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.10" version = "4.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f6b81fb3c84f5563d509c59b5a48d935f689e993afa90fe39047f05adef9142" checksum = "0fbb260a053428790f3de475e304ff84cdbc4face759ea7a3e64c1edd938a7fc"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@@ -71,9 +71,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.10" version = "4.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca6706fd5224857d9ac5eb9355f6683563cc0541c7cd9d014043b57cbec78ac" checksum = "64b17d7ea74e9f833c7dbf2cbe4fb12ff26783eda4782a8975b72f895c9b4d99"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@@ -83,9 +83,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.5.8" version = "4.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@@ -95,15 +95,15 @@ dependencies = [
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
[[package]] [[package]]
name = "colorchoice" name = "colorchoice"
version = "1.0.1" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]] [[package]]
name = "colored" name = "colored"
@@ -123,9 +123,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]] [[package]]
name = "is_terminal_polyfill" name = "is_terminal_polyfill"
version = "1.70.0" version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
@@ -159,9 +159,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.71" version = "2.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "ah" name = "ah-pkg"
version = "0.1.0" version = "0.3.1"
authors = ["Michał Czyż <mike@c2yz.com>"] authors = ["Michał Czyż <mike@c2yz.com>"]
edition = "2021" edition = "2021"
@@ -8,10 +8,34 @@ description = "A declarative package manager for Arch Linux"
homepage = "https://github.com/eRgo35/ah" homepage = "https://github.com/eRgo35/ah"
repository = "https://github.com/eRgo35/ah" repository = "https://github.com/eRgo35/ah"
documentation = "https://github.com/eRgo35/ah" documentation = "https://github.com/eRgo35/ah"
license = "MIT"
keywords = ["archlinux", "declarative", "package", "aur", "paru"] keywords = ["archlinux", "declarative", "package", "aur", "paru"]
license = "MIT"
readme = "README.md" readme = "README.md"
[[bin]]
path = "src/main.rs"
name = "ah"
[dependencies] [dependencies]
clap = { version = "4.5.10", features = ["derive"] } clap = { version = "4.5.10", features = ["derive"] }
colored = "2.1.0" colored = "2.1.0"
# The profile that 'cargo dist' will build with
[profile.dist]
inherits = "release"
lto = "thin"
# Config for 'cargo dist'
[workspace.metadata.dist]
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
cargo-dist-version = "0.20.0"
# CI backends to support
ci = "github"
# The installers to generate for each app
installers = ["shell"]
# Target platforms to build apps for (Rust target-triple syntax)
targets = ["x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl"]
# Path that installers should place binaries in
install-path = "CARGO_HOME"
# Whether to install an updater program
install-updater = false

21
LICENSE.md Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Michał Czyż
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,25 +1,21 @@
# Maintainer: Michał Czyż <mike@c2yz.com> # Maintainer: Michał Czyż <mike@c2yz.com>
pkgname=ah
pkgver=0.1.0 pkgname=ah-pkg-bin
pkgver=0.3.1
pkgrel=1 pkgrel=1
pkgdesc="A declarative package manager for Arch Linux" pkgdesc="A declarative package manager for Arch Linux"
url="https://github.com/eRgo35/ah" url="https://github.com/eRgo35/ah"
license=("MIT") license=("MIT")
arch=("x86_64") arch=("x86_64")
makedepends=("cargo") provides=("ah-pkg")
conflicts=("ah-pkg")
pkgver() { depends=("paru" "topgrade")
(git describe --long --tags || echo "$pkgver") | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g' source=("https://github.com/eRgo35/ah/releases/download/v$pkgver/ah-pkg-x86_64-unknown-linux-gnu.tar.xz")
} sha256sums=("6d1778f508d42a3396e466bf44bd650c2dabcd9552f1f776c1c93019f0c52a68")
build() {
return 0
}
package() { package() {
cd .. cd "$srcdir/ah-pkg-x86_64-unknown-linux-gnu"
usrdir="$pkgdir/usr"
mkdir -p $usrdir
cargo install --no-track --path . --root "$usrdir"
}
install -Dm755 ah -t "$pkgdir/usr/bin"
install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE.md"
}

View File

@@ -4,12 +4,18 @@ A declarative package manager for Arch Linux
## What is ah? ## What is ah?
Arch Helper is a declarative package management tool for Arch Linux. It leverages paru or other package managers for seamless integration. Arch Helper is a declarative package management tool for Arch Linux. It leverages paru and topgrade for package management.
It is currently in early development phase so watch out for bugs! It is currently in early development phase so watch out for potential bugs!
## Installation ## Installation
Check out the [releases](https://github.com/eRgo35/ah/releases) tab for the latest release!
## Building
If you want to build from source, you can do so by following the instructions below.
Install Rust :crab: Install Rust :crab:
```sh ```sh
@@ -23,19 +29,21 @@ $ rustup default stable
``` ```
Clone this repo Clone this repo
```sh ```sh
$ git clone https://github.com/eRgo35/ah $ git clone https://github.com/eRgo35/ah
``` ```
Change directory Change directory
```sh ```sh
$ cd ah $ cd ah
``` ```
Install package Build with cargo
```sh ```sh
$ makepkg -si $ cargo build --release
``` ```
## Usage ## Usage
@@ -47,12 +55,13 @@ Arch Helper is a declarative package management tool for Arch Linux. It leverage
Usage: ah [COMMAND] Usage: ah [COMMAND]
Commands: Commands:
install Install packages install Install packages
upgrade Upgrade packages upgrade Upgrade packages
sync Synchronize packages sync Synchronize packages
remove Remove packages remove Remove packages
find Find packages find Find packages
help Print this message or the help of the given subcommand(s) choose-install Find and install packages
help Print this message or the help of the given subcommand(s)
Options: Options:
-h, --help -h, --help

View File

@@ -1,10 +1,12 @@
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
#[derive(Parser)] #[derive(Parser)]
#[command( #[command(
name = "ah", name = "ah",
author = "Michał Czyż", author = "Michał Czyż",
version = "0.1.0", version = VERSION.unwrap_or("unknown"),
about = "A declarative package manager for Arch Linux", 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." long_about = "Arch Helper is a declarative package management tool for Arch Linux. It leverages paru or other package managers for seamless integration."
)] )]
@@ -35,6 +37,9 @@ pub enum Commands {
#[command(alias = "f", about = "Find packages")] #[command(alias = "f", about = "Find packages")]
Find(Query), Find(Query),
#[command(alias = "fi", about = "Find and install packages")]
ChooseInstall(Query),
} }
#[derive(Args)] #[derive(Args)]

View File

@@ -23,7 +23,6 @@ pub fn read_packages(path: PathBuf) -> Vec<String> {
pub fn append_package(path: PathBuf, package: &str) { pub fn append_package(path: PathBuf, package: &str) {
let mut file = OpenOptions::new() let mut file = OpenOptions::new()
.write(true)
.append(true) .append(true)
.open(path) .open(path)
.expect("Failed to open file"); .expect("Failed to open file");

View File

@@ -15,7 +15,8 @@ fn main() {
Some(cli::Commands::Sync { noconfirm }) => packages::sync(noconfirm), Some(cli::Commands::Sync { noconfirm }) => packages::sync(noconfirm),
Some(cli::Commands::Remove(PackageList { packages })) => packages::remove(packages), Some(cli::Commands::Remove(PackageList { packages })) => packages::remove(packages),
Some(cli::Commands::Find(Query { query })) => packages::find(query), Some(cli::Commands::Find(Query { query })) => packages::find(query),
None => packages::rebuild(true), Some(cli::Commands::ChooseInstall(Query { query })) => packages::choose_install(query),
None => packages::full_upgrade(true),
}; };
if let Err(err) = result { if let Err(err) = result {

View File

@@ -0,0 +1,50 @@
use colored::Colorize;
use std::io::Write;
use std::process::{Command, Stdio};
use crate::packages::PACKAGE_MANAGER;
pub fn choose_install(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 mut child = Command::new(PACKAGE_MANAGER)
.arg("--color")
.arg("always")
.arg("s")
.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 word in query.clone() {
writeln!(stdin, "{}", word).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().red(),
"Package index has not been updated!".bold()
);
Ok(())
}

View File

@@ -1,7 +1,7 @@
use colored::Colorize; use colored::Colorize;
use std::process::Command; use std::process::Command;
const PACKAGE_MANAGER: &str = "paru"; use crate::packages::PACKAGE_MANAGER;
pub fn find(query: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { pub fn find(query: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
println!( println!(

View File

@@ -0,0 +1,32 @@
use colored::Colorize;
use std::process::Command;
use crate::packages::{ask_confirmation, SYSTEM_UPDATER};
pub fn full_upgrade(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
println!(
"{} {}",
"::".bold().green(),
"Initializing full system update...".bold()
);
if !ask_confirmation()? {
return Err("Operation aborted".into());
}
let noconfirm = if noconfirm { "-y" } else { "" };
let mut child = Command::new(SYSTEM_UPDATER)
.arg(noconfirm)
.spawn()
.expect("Failed to execute command");
let status = child.wait().expect("Failed to wait on child");
if !status.success() {
return Err("System upgrade failed".into());
}
println!("{} {}", "::".bold().green(), "System upgraded".bold());
Ok(())
}

View File

@@ -1,10 +1,9 @@
use crate::packages::PACKAGE_MANAGER;
use crate::{file, packages::get_package_path}; use crate::{file, packages::get_package_path};
use colored::Colorize; use colored::Colorize;
use std::io::Write; use std::io::Write;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
const PACKAGE_MANAGER: &str = "paru";
pub fn install(new_packages: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { pub fn install(new_packages: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
println!( println!(
"{} {}", "{} {}",
@@ -24,7 +23,6 @@ pub fn install(new_packages: Vec<String>) -> Result<(), Box<dyn std::error::Erro
.arg("always") .arg("always")
.arg("-S") .arg("-S")
.arg("--needed") .arg("--needed")
// .arg(noconfirm)
.arg("-") .arg("-")
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::inherit()) .stdout(Stdio::inherit())

View File

@@ -2,20 +2,27 @@ use colored::Colorize;
use std::io::{self, Write}; use std::io::{self, Write};
use std::path::PathBuf; use std::path::PathBuf;
pub mod choose_install;
pub mod find; pub mod find;
pub mod full_upgrade;
pub mod install; pub mod install;
pub mod rebuild; pub mod rebuild;
pub mod remove; pub mod remove;
pub mod sync; pub mod sync;
pub mod upgrade; pub mod upgrade;
pub use choose_install::choose_install;
pub use find::find; pub use find::find;
pub use full_upgrade::full_upgrade;
pub use install::install; pub use install::install;
pub use rebuild::rebuild; pub use rebuild::rebuild;
pub use remove::remove; pub use remove::remove;
pub use sync::sync; pub use sync::sync;
pub use upgrade::upgrade; pub use upgrade::upgrade;
const SYSTEM_UPDATER: &str = "topgrade";
const PACKAGE_MANAGER: &str = "paru";
fn get_package_path() -> PathBuf { fn get_package_path() -> PathBuf {
let home_dir = std::env::var("HOME").unwrap(); let home_dir = std::env::var("HOME").unwrap();
@@ -23,11 +30,7 @@ fn get_package_path() -> PathBuf {
} }
fn ask_confirmation() -> Result<bool, io::Error> { fn ask_confirmation() -> Result<bool, io::Error> {
print!( print!("{} Do you want to continue? [Y/n] ", "::".bold().blue());
"{} {}",
"::".bold().blue(),
"Do you want to continue? [Y/n] "
);
io::stdout().flush()?; io::stdout().flush()?;
let mut input = String::new(); let mut input = String::new();

View File

@@ -3,9 +3,7 @@ use std::io::Write;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use crate::file; use crate::file;
use crate::packages::{ask_confirmation, get_package_path}; use crate::packages::{ask_confirmation, get_package_path, PACKAGE_MANAGER};
const PACKAGE_MANAGER: &str = "paru";
pub fn rebuild(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> { pub fn rebuild(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
println!( println!(

View File

@@ -1,10 +1,9 @@
use crate::packages::PACKAGE_MANAGER;
use crate::{file, packages::get_package_path}; use crate::{file, packages::get_package_path};
use colored::Colorize; use colored::Colorize;
use std::io::Write; use std::io::Write;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
const PACKAGE_MANAGER: &str = "paru";
pub fn remove(unwanted_packages: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { pub fn remove(unwanted_packages: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
println!("{} {}", "::".bold().green(), "Removing packages...".bold()); println!("{} {}", "::".bold().green(), "Removing packages...".bold());

View File

@@ -3,9 +3,7 @@ use std::io::Write;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use crate::file; use crate::file;
use crate::packages::{ask_confirmation, get_package_path}; use crate::packages::{ask_confirmation, get_package_path, PACKAGE_MANAGER};
const PACKAGE_MANAGER: &str = "paru";
pub fn sync(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> { pub fn sync(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
println!("{} {}", "::".bold().green(), "Syncing packages...".bold()); println!("{} {}", "::".bold().green(), "Syncing packages...".bold());

View File

@@ -1,9 +1,7 @@
use colored::Colorize; use colored::Colorize;
use std::process::Command; use std::process::Command;
use crate::packages::ask_confirmation; use crate::packages::{ask_confirmation, PACKAGE_MANAGER};
const PACKAGE_MANAGER: &str = "paru";
pub fn upgrade(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> { pub fn upgrade(noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
println!("{} {}", "::".bold().green(), "Upgrading packages...".bold()); println!("{} {}", "::".bold().green(), "Upgrading packages...".bold());