netmito 0.6.8

A Unified Distributed Transport Evaluation Framework
Documentation
use clap::{Args, Subcommand};
use serde::{Deserialize, Serialize};

use crate::entity::role::UserGroupRole;

use super::{parse_key_val_colon, AttachmentsArgs};

#[derive(Serialize, Debug, Deserialize, Args, derive_more::From, Clone)]
pub struct GroupsArgs {
    #[command(subcommand)]
    pub command: GroupsCommands,
}

#[derive(Subcommand, Serialize, Debug, Deserialize, derive_more::From, Clone)]
pub enum GroupsCommands {
    /// Create a new group
    Create(GroupCreateArgs),
    /// Get the information of a group
    Get(GroupGetArgs),
    /// Update the roles of users to a group
    UpdateUser(GroupUpdateUserArgs),
    /// Remove the accessibility of users from a group
    RemoveUser(RemoveUserGroupArgs),
    /// Query, upload, download or delete an attachment
    Attachments(AttachmentsArgs),
}

#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct GroupCreateArgs {
    /// The name of the group
    pub group: String,
}

#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct GroupGetArgs {
    /// The name of the group
    pub group: String,
}

#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct GroupUpdateUserArgs {
    /// The name of the group
    pub group: String,
    /// The username and role of the user to the group
    #[arg(num_args = 0.., value_parser = parse_key_val_colon::<String, UserGroupRole>)]
    pub roles: Vec<(String, UserGroupRole)>,
}

#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct RemoveUserGroupArgs {
    /// The name of the group
    pub group: String,
    /// The username of the user
    #[arg(num_args = 0..)]
    pub users: Vec<String>,
}