eio_okta_client/
command.rs

1mod standalone;
2
3use clap::{Parser, Subcommand};
4use eio_okta_api::v1::{groups, users};
5
6#[derive(Debug, Parser)]
7#[group(skip)]
8pub struct Command {
9  #[command(flatten)]
10  client: crate::Options,
11  #[command(subcommand)]
12  operation: Operation,
13  #[arg(long)]
14  pretty: bool,
15}
16
17#[derive(Debug, Subcommand)]
18#[remain::sorted]
19pub enum Operation {
20  AssignUserToGroup(groups::AssignUserToGroup),
21  GetGroup(groups::GetGroup),
22  GetUser(users::GetUser),
23  ListAssignedApplicationsForGroup(groups::ListAssignedApplicationsForGroup),
24  ListGroups(groups::ListGroups),
25  ListGroupUsers(groups::ListGroupUsers),
26  ListUsers(users::ListUsers),
27  UnassignUserFromGroup(groups::UnassignUserFromGroup),
28}
29
30impl Command {
31  #[remain::check]
32  pub fn run(self) -> Result<(), crate::Error> {
33    let Command {
34      client,
35      operation,
36      pretty,
37    } = self;
38
39    let client = crate::Client::from(client);
40
41    let json = {
42      #[remain::sorted]
43      match operation {
44        Operation::AssignUserToGroup(endpoint) => client.json(endpoint, pretty),
45        Operation::GetGroup(endpoint) => client.json(endpoint, pretty),
46        Operation::GetUser(endpoint) => client.json(endpoint, pretty),
47        Operation::ListAssignedApplicationsForGroup(endpoint) => client.autopaginate_json(endpoint, pretty),
48        Operation::ListGroups(endpoint) => client.autopaginate_json(endpoint, pretty),
49        Operation::ListGroupUsers(endpoint) => client.autopaginate_json(endpoint, pretty),
50        Operation::ListUsers(endpoint) => client.autopaginate_json(endpoint, pretty),
51        Operation::UnassignUserFromGroup(endpoint) => client.json(endpoint, pretty),
52      }
53    }?;
54
55    println!("{json}");
56
57    Ok(())
58  }
59}
60
61pub use standalone::Standalone;