use crate::common::Execute;
use clap::Subcommand;
use std::error::Error;
use tabled::{builder::Builder, settings::Style};
#[derive(Subcommand, Debug)]
pub(crate) enum AuthenticationStrategyCommand {
#[clap(about = "List authentication strategies")]
List {},
}
impl Execute for AuthenticationStrategyCommand {
fn execute(&self, api: wikijs::Api) -> Result<(), Box<dyn Error>> {
match self {
AuthenticationStrategyCommand::List {} => {
authentication_strategy_list(api)
}
}
}
}
fn authentication_strategy_list(
api: wikijs::Api,
) -> Result<(), Box<dyn Error>> {
let providers = api.authentication_strategy_list()?;
let mut builder = Builder::new();
builder.push_record([
"key",
"title",
"is_available",
]);
for provider in providers {
builder.push_record([
provider.key.as_str(),
provider.title.as_str(),
match provider.is_available {
Some(true) => "true",
Some(false) => "false",
None => "",
},
]);
}
println!("{}", builder.build().with(Style::rounded()));
Ok(())
}