This commit is contained in:
chaos 2024-11-21 15:10:34 +00:00
parent 42dc2d0b26
commit 114b1d1813
3 changed files with 14 additions and 8 deletions

View file

@ -2,6 +2,7 @@ use clap::{Parser, Subcommand};
#[derive(Debug, Clone, Subcommand)]
#[command(rename_all = "camelCase")]
#[command(flatten_help = false)]
pub enum Commands {
PrintExperience(crate::commands::print_experience::PrintExperienceArgs),
}
@ -9,22 +10,23 @@ pub enum Commands {
// TODO: add env vars back to this,
// clashes with multiple=false when one set as env and other as arg
#[derive(Debug, Clone, clap::Args)]
#[group(required = false, multiple = false)]
pub struct JournalFileArgs {
#[group(id = "journal_location", multiple = false)]
pub struct JournalLocationArgs {
// journal file is writable
// #[arg(group = "journal_file_args", global = true, long)]
// pub journal_file: Option<String>,
#[arg(group = "journal_location", global = true, long)]
pub journal_file: Option<String>,
// export file is read-only
#[arg(group = "journal_file", global = true, long)]
#[arg(group = "journal_location", global = true, long)]
pub psychonaut_export_file: Option<String>,
}
#[derive(Debug, Parser)]
#[command(flatten_help = false)]
pub struct Args {
#[command(subcommand)]
pub command: Commands,
#[command(flatten)]
pub journal_file_args: JournalFileArgs,
pub journal_location: Option<JournalLocationArgs>,
}

View file

@ -8,8 +8,8 @@ use crate::formatting::format_experience_title;
use crate::utils::load_journal;
#[derive(Debug, Clone, clap::Args)]
#[group(requires = "journal_location")]
pub struct PrintExperienceArgs {
#[arg(requires = "journal_file")]
pub experience_title: String,
#[arg(long)]
@ -42,7 +42,9 @@ pub fn print_experience(
) -> Result<(), Box<dyn std::error::Error>> {
let journal = load_journal(
&global_args
.journal_file_args
.journal_location
.clone()
.unwrap()
.psychonaut_export_file
.clone()
.unwrap(),

View file

@ -17,6 +17,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
match command {
args::Commands::PrintExperience(print_experience_args) => {
println!("{:#?}", print_experience_args);
print_experience(&args, &print_experience_args)?
}
}