vieter/src/console/aur/aur.v

63 lines
1.4 KiB
Coq
Raw Normal View History

2022-06-22 16:19:07 +02:00
module aur
import cli
import console
2022-06-22 16:38:53 +02:00
import client
2022-11-01 21:43:25 +01:00
import aur
import conf as vconf
2022-06-22 16:19:07 +02:00
2022-06-22 16:38:53 +02:00
struct Config {
address string [required]
api_key string [required]
}
// cmd returns the cli module for interacting with the AUR API.
2022-06-22 16:19:07 +02:00
pub fn cmd() cli.Command {
return cli.Command{
name: 'aur'
description: 'Interact with the AUR.'
commands: [
cli.Command{
name: 'search'
description: 'Search for packages.'
required_args: 1
2022-11-01 21:10:45 +01:00
execute: fn (cmd cli.Command) ! {
2022-06-22 16:19:07 +02:00
c := aur.new()
2022-11-01 21:10:45 +01:00
pkgs := c.search(cmd.args[0])!
2022-06-22 16:19:07 +02:00
data := pkgs.map([it.name, it.description])
2022-11-01 21:10:45 +01:00
println(console.pretty_table(['name', 'description'], data)!)
2022-06-22 16:19:07 +02:00
}
},
2022-06-22 16:38:53 +02:00
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
2022-11-01 21:10:45 +01:00
execute: fn (cmd cli.Command) ! {
config_file := cmd.flags.get_string('config-file')!
conf_ := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
2022-06-22 16:38:53 +02:00
c := aur.new()
2022-11-01 21:10:45 +01:00
pkgs := c.info(cmd.args[1..])!
2022-06-22 16:38:53 +02:00
vc := client.new(conf_.address, conf_.api_key)
2022-06-22 16:38:53 +02:00
for pkg in pkgs {
vc.add_target(
kind: 'git'
2023-02-08 11:00:17 +01:00
url: 'https://aur.archlinux.org/${pkg.package_base}' + '.git'
2022-06-22 16:38:53 +02:00
repo: cmd.args[0]
) or {
2023-02-08 11:00:17 +01:00
println('Failed to add ${pkg.name}: ${err.msg()}')
2022-06-22 16:38:53 +02:00
continue
}
2023-02-08 11:00:17 +01:00
println('Added ${pkg.name}' + '.')
2022-06-22 16:38:53 +02:00
}
}
},
2022-06-22 16:19:07 +02:00
]
}
}