From cac74db086e0163f6097f62a518746904151328c Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Wed, 28 Dec 2022 21:52:16 +0100 Subject: [PATCH] feat(console): add commands for removing repos, arch-repos, packages --- CHANGELOG.md | 4 +++ src/console/repos/repos.v | 52 +++++++++++++++++++++++++++++++++++++++ src/main.v | 2 ++ 3 files changed, 58 insertions(+) create mode 100644 src/console/repos/repos.v diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e67899..55e6d65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://git.rustybever.be/vieter-v/vieter/src/branch/dev) +### Added + +* CLI commands for removing packages, arch-repos & repositories + ## [0.5.0-rc.2](https://git.rustybever.be/vieter-v/vieter/src/tag/0.5.0-rc.2) ### Added diff --git a/src/console/repos/repos.v b/src/console/repos/repos.v new file mode 100644 index 0000000..729208e --- /dev/null +++ b/src/console/repos/repos.v @@ -0,0 +1,52 @@ +module repos + +import cli +import conf as vconf +import client + +struct Config { + address string [required] + api_key string [required] +} + +// cmd returns the cli module that handles modifying the repository contents. +pub fn cmd() cli.Command { + return cli.Command{ + name: 'repos' + description: 'Interact with the repositories & packages stored on the server.' + commands: [ + cli.Command{ + name: 'remove' + required_args: 1 + usage: 'repo [arch [pkgname]]' + description: 'Remove a repo, arch-repo, or package from the server.' + flags: [ + cli.Flag{ + name: 'force' + flag: cli.FlagType.bool + }, + ] + execute: fn (cmd cli.Command) ! { + config_file := cmd.flags.get_string('config-file')! + conf := vconf.load(prefix: 'VIETER_', default_path: config_file)! + + if cmd.args.len < 3 { + if !cmd.flags.get_bool('force')! { + return error('Removing an arch-repo or repository is a very destructive command. If you really do wish to perform this operation, explicitely add the --force flag.') + } + } + + client := client.new(conf.address, conf.api_key) + + if cmd.args.len == 1 { + client.remove_repo(cmd.args[0])! + } else if cmd.args.len == 2 { + client.remove_arch_repo(cmd.args[0], cmd.args[1])! + } else { + client.remove_package(cmd.args[0], cmd.args[1], cmd.args[2])! + } + } + }, + ] + } +} diff --git a/src/main.v b/src/main.v index eda38e7..8d4ca04 100644 --- a/src/main.v +++ b/src/main.v @@ -8,6 +8,7 @@ import console.logs import console.schedule import console.man import console.aur +import console.repos import cron import agent @@ -48,6 +49,7 @@ fn main() { man.cmd(), aur.cmd(), agent.cmd(), + repos.cmd(), ] } app.setup()