refactor: move subcommands aside

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-04-30 20:18:54 +02:00
parent 8e4b46d2d7
commit 469f28f65d
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912

View File

@ -34,6 +34,21 @@ enum Commands {
host: SocketAddr,
},
Exec {
#[command(subcommand)]
commands: ExecCommands,
},
Query {
#[command(subcommand)]
commands: QueryCommands,
},
Info {},
}
#[derive(Subcommand)]
enum ExecCommands {
CreateRoot {
#[arg(long = "root")]
root: String,
@ -46,7 +61,10 @@ enum Commands {
#[arg(long = "path")]
path: Option<String>,
},
}
#[derive(Subcommand)]
enum QueryCommands {
Get {
#[arg(long = "root")]
root: String,
@ -54,8 +72,6 @@ enum Commands {
#[arg(long = "path")]
path: Option<String>,
},
Info {},
}
#[tokio::main]
@ -100,10 +116,11 @@ async fn main() -> anyhow::Result<()> {
.await
.unwrap();
}
Some(Commands::CreateRoot { root }) => state
Some(Commands::Exec { commands }) => match commands {
ExecCommands::CreateRoot { root } => state
.commander
.execute(commander::Command::CreateRoot { root })?,
Some(Commands::CreateSection { root, path }) => {
ExecCommands::CreateSection { root, path } => {
state.commander.execute(commander::Command::CreateSection {
root,
path: path
@ -114,7 +131,9 @@ async fn main() -> anyhow::Result<()> {
.collect::<Vec<String>>(),
})?
}
Some(Commands::Get { root, path }) => {
},
Some(Commands::Query { commands }) => match commands {
QueryCommands::Get { root, path } => {
let res = state.querier.get(
&root,
path.unwrap_or_default()
@ -126,6 +145,7 @@ async fn main() -> anyhow::Result<()> {
println!("{}", output);
}
},
Some(Commands::Info {}) => {
println!("graph stored at: {}", state.storage.info()?)
}