mod get;
mod local;
mod schema;
mod set;
mod unset;
use std::str::FromStr;
use crate::cmd::AxCliCommand;
use ax_core::settings::{Scope, ScopeError};
use futures::Future;
use get::GetOpt;
use local::SettingsLocalOpts;
use schema::SchemaOpt;
use set::SetOpt;
use std::convert::TryFrom;
use unset::UnsetOpt;
#[derive(clap::Subcommand, Debug, Clone)]
pub enum SettingsOpts {
Set(SetOpt),
Unset(UnsetOpt),
Get(GetOpt),
Schema(SchemaOpt),
#[command(subcommand, arg_required_else_help(true))]
Local(SettingsLocalOpts),
}
pub fn run(opts: SettingsOpts, json: bool) -> Box<dyn Future<Output = ()> + Unpin> {
match opts {
SettingsOpts::Set(opt) => set::SettingsSet::output(opt, json),
SettingsOpts::Get(opt) => get::SettingsGet::output(opt, json),
SettingsOpts::Schema(opt) => schema::SettingsSchema::output(opt, json),
SettingsOpts::Unset(opt) => unset::SettingsUnset::output(opt, json),
SettingsOpts::Local(opt) => local::run(opt, json),
}
}
fn parse_scope(value: &str) -> Result<Scope, ScopeError> {
if !value.starts_with('/') {
return Err(ScopeError::MalformedScope(value.to_string()));
}
if value == "/" {
Scope::from_str("com.actyx")
} else {
Scope::try_from(format!("com.actyx{}", value))
}
}
fn print_scope(scope: Scope) -> String {
let scope = scope.drop_first();
if scope.is_root() {
"/".to_string()
} else {
format!("/{}", scope)
}
}