progress-pile/dpts-cli/src/record.rs

60 lines
1.2 KiB
Rust
Raw Normal View History

2025-04-24 09:26:24 +09:00
use chrono::prelude::*;
use clap::{Args, Subcommand};
2025-04-27 19:22:46 +09:00
use dpts_core::error::Error;
2025-04-27 08:36:57 +09:00
use std::str::FromStr;
2025-04-24 09:26:24 +09:00
2025-04-27 08:36:57 +09:00
#[derive(Args, Clone, Debug)]
pub struct AchievementArgValues {
2025-04-24 09:26:24 +09:00
pub label: String,
2025-04-27 08:36:57 +09:00
pub value: i8,
}
impl FromStr for AchievementArgValues {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Error> {
let strvec: Vec<&str> = s.split(':').collect();
Ok(AchievementArgValues{
label: strvec.get(0).unwrap().to_string(),
value: strvec.get(1).unwrap().parse()?
})
}
}
#[derive(Args, Clone, Debug)]
pub struct RecordAddArgs {
2025-04-24 09:26:24 +09:00
#[arg(short, long)]
pub comment: Option<String>,
#[arg(short, long)]
pub time: Option<DateTime<Utc>>,
2025-04-27 08:36:57 +09:00
//pub achievements: Vec<String>,
2025-04-24 09:26:24 +09:00
}
2025-04-27 08:36:57 +09:00
2025-04-24 09:26:24 +09:00
impl RecordAddArgs {
2025-04-27 08:36:57 +09:00
pub fn run(self) -> Result<(), Error> {
2025-04-24 09:26:24 +09:00
unimplemented!();
}
}
2025-04-27 08:36:57 +09:00
#[derive(Clone, Debug, Subcommand)]
2025-04-24 09:26:24 +09:00
pub enum RecordCommand {
Add(RecordAddArgs),
}
2025-04-27 08:36:57 +09:00
#[derive(Args, Clone, Debug)]
2025-04-24 09:26:24 +09:00
pub struct RecordArgs {
#[command(subcommand)]
command: RecordCommand,
}
impl RecordArgs {
2025-04-27 08:36:57 +09:00
pub fn run(self) -> Result<(), Error> {
match self.command {
2025-04-24 09:26:24 +09:00
RecordCommand::Add(x) => x.run(),
}
}
}