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