feat: add print arguments
This commit is contained in:
18
src/lib.rs
18
src/lib.rs
@@ -29,17 +29,20 @@ pub enum Commands {
|
||||
#[command(about = "Install RPM fusion")]
|
||||
InstallRpmFusion,
|
||||
|
||||
#[command(about = "Add user to groups")]
|
||||
AddUserToGroups(AddUserToGroupsCommand),
|
||||
#[command(about = "Add groups to a user")]
|
||||
AddGroups(AddGroupsCommand),
|
||||
|
||||
#[command(about = "Manage packages")]
|
||||
Package(PackageCommand),
|
||||
}
|
||||
|
||||
#[derive(Args, Debug, PartialEq)]
|
||||
pub struct AddUserToGroupsCommand {
|
||||
#[arg(short, long)]
|
||||
pub struct AddGroupsCommand {
|
||||
#[arg(short, long, help = "The user to add to the groups, current user by default")]
|
||||
pub user: Option<String>,
|
||||
|
||||
#[arg(short, long, help = "Print the groups without changing anything")]
|
||||
pub print: bool,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug, PartialEq)]
|
||||
@@ -62,9 +65,12 @@ pub enum AddRepoSubCommand {
|
||||
|
||||
#[derive(Args, Debug, PartialEq, Clone)]
|
||||
pub struct PackageCommand {
|
||||
#[arg(short, long)]
|
||||
#[arg(short, long, help = "Whenever to remove instead of install")]
|
||||
pub remove: bool,
|
||||
|
||||
#[arg(short, long, help = "Print packages of the list without changing anything")]
|
||||
pub print: bool,
|
||||
|
||||
#[command(subcommand)]
|
||||
pub command: PackageSubCommand,
|
||||
}
|
||||
@@ -92,7 +98,7 @@ pub enum PackageSubCommand {
|
||||
|
||||
#[derive(Args, Debug, PartialEq, Clone)]
|
||||
pub struct CustomListCommand {
|
||||
#[arg(short, long)]
|
||||
#[arg(short, long, help = "The file to read the list from")]
|
||||
pub file: String,
|
||||
}
|
||||
|
||||
|
||||
27
src/main.rs
27
src/main.rs
@@ -33,8 +33,8 @@ fn main() {
|
||||
log::error!("Error installing RPM Fusion: {}", e);
|
||||
}
|
||||
}
|
||||
Commands::AddUserToGroups(add_user_command) => {
|
||||
if let Err(e) = add_user_to_groups(add_user_command) {
|
||||
Commands::AddGroups(add_user_command) => {
|
||||
if let Err(e) = add_groups(add_user_command) {
|
||||
log::error!("Error adding user to groups: {}", e);
|
||||
}
|
||||
}
|
||||
@@ -51,13 +51,15 @@ fn main() {
|
||||
success!("Bye :)");
|
||||
}
|
||||
|
||||
fn add_user_to_groups(add_user_command: AddUserToGroupsCommand) -> Result<()> {
|
||||
let user = add_user_command.user.unwrap_or_else(|| {
|
||||
log::info!("No user specified, using current user");
|
||||
whoami::username()
|
||||
});
|
||||
fn add_groups(add_user_command: AddGroupsCommand) -> Result<()> {
|
||||
let groups = include_str!("../data/user_groups.txt").to_string();
|
||||
|
||||
if add_user_command.print {
|
||||
log::info!("Printing groups...");
|
||||
println!("{}", groups);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let groups = groups
|
||||
.lines()
|
||||
.map(|line| line.trim())
|
||||
@@ -82,6 +84,11 @@ fn add_user_to_groups(add_user_command: AddUserToGroupsCommand) -> Result<()> {
|
||||
}
|
||||
|
||||
let groups = groups.join(",");
|
||||
|
||||
let user = add_user_command.user.unwrap_or_else(|| {
|
||||
log::info!("No user specified, using current user");
|
||||
whoami::username()
|
||||
});
|
||||
|
||||
log::info!("Adding user {} to groups: {}", user, groups);
|
||||
|
||||
@@ -214,6 +221,12 @@ fn manage_package(package_command: PackageCommand) -> Result<()> {
|
||||
}
|
||||
};
|
||||
|
||||
if package_command.print {
|
||||
log::info!("Printing package list...");
|
||||
println!("{}", list);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
manage_list(list, package_command.remove)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user