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