From 1a940f2f98e6c2c7794e4f06b2913a32316cfbfd Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 22 Jun 2022 16:38:53 +0200 Subject: [PATCH] feat(cli): added "aur add" command --- CHANGELOG.md | 1 + src/console/aur/aur.v | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf2b8293..a03c18cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 URL to a PKGBUILD * Targets with kind 'url' can provide a direct URL to a PKGBUILD instead of providing a Git repository +* CLI commands for searching the AUR & directly adding packages ### Changed diff --git a/src/console/aur/aur.v b/src/console/aur/aur.v index 3f20dfca..c98f8e68 100644 --- a/src/console/aur/aur.v +++ b/src/console/aur/aur.v @@ -2,8 +2,16 @@ module aur import cli import console +import client import vieter_v.aur +import vieter_v.conf as vconf +struct Config { + address string [required] + api_key string [required] +} + +// cmd returns the cli module for interacting with the AUR API. pub fn cmd() cli.Command { return cli.Command{ name: 'aur' @@ -21,6 +29,34 @@ pub fn cmd() cli.Command { println(console.pretty_table(['name', 'description'], data)?) } }, + cli.Command{ + name: 'add' + usage: 'repo pkg-name [pkg-name...]' + description: 'Add the given AUR package(s) to Vieter. Non-existent packages will be silently ignored.' + required_args: 2 + execute: fn (cmd cli.Command) ? { + config_file := cmd.flags.get_string('config-file')? + conf := vconf.load(prefix: 'VIETER_', default_path: config_file)? + + c := aur.new() + pkgs := c.info(cmd.args[1..])? + + vc := client.new(conf.address, conf.api_key) + + for pkg in pkgs { + vc.add_target( + kind: 'git' + url: 'https://aur.archlinux.org/$pkg.package_base' + '.git' + repo: cmd.args[0] + ) or { + println('Failed to add $pkg.name: $err.msg()') + continue + } + + println('Added $pkg.name' + '.') + } + } + }, ] } }