Skip to main content

parley/cli/
args.rs

1use std::str::FromStr;
2
3use crate::domain::{
4    ai::{AiProvider, AiSessionMode},
5    review::{Author, DiffSide, ReviewState},
6};
7
8#[derive(Debug, Clone)]
9pub struct StateArg(pub ReviewState);
10
11impl FromStr for StateArg {
12    type Err = String;
13
14    fn from_str(input: &str) -> Result<Self, Self::Err> {
15        match input {
16            "open" => Ok(Self(ReviewState::Open)),
17            "under_review" => Ok(Self(ReviewState::UnderReview)),
18            "done" => Ok(Self(ReviewState::Done)),
19            _ => Err(format!("invalid state: {input}")),
20        }
21    }
22}
23
24#[derive(Debug, Clone)]
25pub struct SideArg(pub DiffSide);
26
27impl FromStr for SideArg {
28    type Err = String;
29
30    fn from_str(input: &str) -> Result<Self, Self::Err> {
31        match input {
32            "left" => Ok(Self(DiffSide::Left)),
33            "right" => Ok(Self(DiffSide::Right)),
34            _ => Err(format!("invalid side: {input}")),
35        }
36    }
37}
38
39#[derive(Debug, Clone)]
40pub struct AuthorArg(pub Author);
41
42impl FromStr for AuthorArg {
43    type Err = String;
44
45    fn from_str(input: &str) -> Result<Self, Self::Err> {
46        match input {
47            "user" => Ok(Self(Author::User)),
48            "ai" => Ok(Self(Author::Ai)),
49            _ => Err(format!("invalid author: {input}")),
50        }
51    }
52}
53
54#[derive(Debug, Clone)]
55pub struct AiProviderArg(pub AiProvider);
56
57impl FromStr for AiProviderArg {
58    type Err = String;
59
60    fn from_str(input: &str) -> Result<Self, Self::Err> {
61        input.parse::<AiProvider>().map(Self)
62    }
63}
64
65#[derive(Debug, Clone)]
66pub struct AiSessionModeArg(pub AiSessionMode);
67
68impl FromStr for AiSessionModeArg {
69    type Err = String;
70
71    fn from_str(input: &str) -> Result<Self, Self::Err> {
72        input.parse::<AiSessionMode>().map(Self)
73    }
74}