Setup commands moved to a subcommand menu

This commit is contained in:
JP Stringham
2026-03-06 16:10:53 -05:00
parent e8c844a282
commit 2ea28220b3
4 changed files with 73 additions and 50 deletions

View File

@@ -10,12 +10,10 @@
mod app;
pub mod json_types;
use json_types::*;
use std::io::Write;
use clap::{CommandFactory, Parser, Subcommand};
use colored::Colorize;
use colored::{ColoredString, Colorize};
use enum_iterator::Sequence;
use crate::app::App;
@@ -62,10 +60,16 @@ fn main() {
};
match cli.command {
Commands::GetAuthMetadata => app.get_auth_metadata(),
Commands::RegisterClient => app.register_client(),
Commands::AuthorizeDevice => app.authorize_device(),
Commands::RefreshAuth => app.refresh_auth(),
Commands::Setup(sub_args) => {
println!("subargs: {:?}", sub_args);
match sub_args.command {
SetupCommands::GetAuthMetadata => app.get_auth_metadata(),
SetupCommands::RegisterClient => app.register_client(),
SetupCommands::AuthorizeDevice => app.authorize_device(),
SetupCommands::RefreshAuth => app.refresh_auth(),
}
}
Commands::ShowOauthLinks => app.show_oauth_links(),
}
}
@@ -149,11 +153,31 @@ struct Cli {
command: Commands,
}
#[derive(Debug, Subcommand, PartialEq, Eq, Sequence)]
#[derive(Debug, Subcommand)]
enum Commands {
#[command(subcommand_help_heading = "Setup Auth for Admin API")]
#[command(arg_required_else_help = true)]
Setup(SetupCommandArgs),
ShowOauthLinks,
}
#[derive(Debug, Parser)]
struct SetupCommandArgs {
#[command(subcommand)]
command: SetupCommands,
}
#[derive(Debug, Subcommand, PartialEq, Eq, Sequence)]
enum SetupCommands {
GetAuthMetadata,
RegisterClient,
AuthorizeDevice,
RefreshAuth,
ShowOauthLinks,
}
fn quick_format_bool(b: bool) -> ColoredString {
match b {
true => "true".bright_green(),
false => "false".red(),
}
}