feat: WIP setup actions

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-10-24 22:59:27 +02:00
parent dfa70b3485
commit db49af5fa2
16 changed files with 815 additions and 11 deletions

View File

@@ -1,17 +1,24 @@
use std::{borrow::BorrowMut, io::Write};
use std::io::Write;
use anyhow::anyhow;
use clap::{FromArgMatches, Subcommand};
use get_command::GetCommand;
use crate::{cuddle_state::Cuddle, state::ValidatedState};
mod get_command;
mod init_command;
pub struct Cli {
cli: clap::Command,
cuddle: Cuddle<ValidatedState>,
}
#[derive(clap::Parser, Debug)]
pub enum Subcommands {
Init(init_command::InitCommand),
}
impl Cli {
pub fn new(cuddle: Cuddle<ValidatedState>) -> Self {
let cli = clap::Command::new("cuddle").subcommand_required(true);
@@ -24,6 +31,8 @@ impl Cli {
self.cli = self.cli.subcommands(commands);
self.cli = Subcommands::augment_subcommands(self.cli);
// TODO: Add global
// TODO: Add components
@@ -44,9 +53,17 @@ impl Cli {
}
pub async fn execute(self) -> anyhow::Result<()> {
match self
.cli
.get_matches_from(std::env::args())
let matches = self.cli.get_matches_from(std::env::args());
if let Ok(subcommand) = Subcommands::from_arg_matches(&matches) {
match subcommand {
Subcommands::Init(init_command) => {
init_command.execute(&self.cuddle).await?;
}
}
}
match matches
.subcommand()
.ok_or(anyhow::anyhow!("failed to find subcommand"))?
{