feat: add cli packie repo-admin
Signed-off-by: sisungo <[email protected]>
This commit is contained in:
@@ -4,6 +4,7 @@ mod initdb;
|
||||
mod install;
|
||||
mod print;
|
||||
mod remove;
|
||||
mod repo_admin;
|
||||
|
||||
use clap::Parser;
|
||||
use rust_i18n::t;
|
||||
@@ -36,6 +37,9 @@ enum Subcommand {
|
||||
|
||||
/// Remove one or more packages
|
||||
Remove(remove::Cli),
|
||||
|
||||
/// Administrate repository service
|
||||
RepoAdmin(repo_admin::Cli),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -57,6 +61,7 @@ fn main() {
|
||||
Subcommand::Install(cli) => install::main(cli),
|
||||
Subcommand::Print(cli) => print::main(cli),
|
||||
Subcommand::Remove(cli) => remove::main(cli),
|
||||
Subcommand::RepoAdmin(cli) => repo_admin::main(cli),
|
||||
};
|
||||
if let Err(err) = result {
|
||||
eprintln!("{}", t!("main.error", error = err));
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
use anyhow::anyhow;
|
||||
use clap::Parser;
|
||||
use packie::repo::RepoServeDir;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Cli {
|
||||
/// Path of the repository serve directory
|
||||
repo: PathBuf,
|
||||
|
||||
/// Add package(s) to the repository
|
||||
#[arg(long, short)]
|
||||
add_package: Option<Vec<PathBuf>>,
|
||||
}
|
||||
|
||||
pub fn main(cli: Cli) -> anyhow::Result<()> {
|
||||
let mut repo = RepoServeDir::open(cli.repo)?;
|
||||
|
||||
for add_package in cli.add_package.into_iter().flatten() {
|
||||
repo.add_package(add_package).map_err(|x| anyhow!("{x}"))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user