use std::path::PathBuf;
use clap::{Args, Parser, Subcommand, ValueEnum};
#[derive(Debug, Parser)]
#[command(
name = "diurn",
version,
about,
long_about = None,
// Subcommand-less invocation should show help, not an opaque error.
arg_required_else_help = true
)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
#[arg(long, short, global = true, value_enum)]
pub format: Option<Format>,
#[arg(long, short, global = true)]
pub quiet: bool,
}
#[derive(Debug, Subcommand)]
pub enum Command {
#[command(
subcommand,
long_about = "ISO 10383 Market Identifier Codes. No API key, and no \
network except for `fetch`.\n\n\
Nothing is bundled with this command. Run `diurn mic fetch` once; \
after that every command uses the newest registry in your data \
directory. Point at a specific file with --path, and see what you \
have with `diurn mic vintages`."
)]
Mic(MicCommand),
#[command(
long_about = "Market calendars and trading hours.\n\n\
Calendar commands require DIURN_API_KEY — get one at https://diurn.io\n\n\
The namespace is reserved but not yet implemented. When it lands it \
will be a thin wrapper over the `diurn` client crate, so the CLI \
exercises the same library everyone else integrates against.",
after_help = "PLANNED COMMANDS:\n \
diurn cal status <id> open or closed at an instant\n \
diurn cal next-close <id> next session close\n \
diurn cal next-open <id> next session open\n \
diurn cal sessions <id> sessions over a date range\n \
diurn cal coverage which calendars are verified how far\n\n\
MIC commands need no key and work offline: try `diurn mic --help`."
)]
Cal(CalArgs),
}
#[derive(Debug, Subcommand)]
pub enum MicCommand {
Load {
path: PathBuf,
#[command(flatten)]
vintage: VintageArgs,
#[arg(long)]
issues: bool,
},
Get {
mic: String,
#[arg(long)]
segments: bool,
#[command(flatten)]
source: SourceArgs,
},
List {
#[arg(long)]
country: Option<String>,
#[arg(long)]
status: Option<String>,
#[arg(long)]
category: Option<String>,
#[arg(long)]
operating: bool,
#[arg(long)]
pending: bool,
#[arg(long)]
limit: Option<usize>,
#[command(flatten)]
source: SourceArgs,
},
Segments {
mic: String,
#[command(flatten)]
source: SourceArgs,
},
Validate {
path: PathBuf,
#[command(flatten)]
vintage: VintageArgs,
},
Diff {
old: PathBuf,
new: PathBuf,
},
Fetch {
#[arg(long, short)]
out: Option<PathBuf>,
#[arg(long)]
published: Option<String>,
},
Vintages,
}
#[derive(Debug, Args)]
pub struct SourceArgs {
#[arg(long, short = 'p', value_name = "FILE")]
pub path: Option<PathBuf>,
#[arg(long, requires = "path")]
pub published: Option<String>,
}
#[derive(Debug, Args)]
pub struct VintageArgs {
#[arg(long)]
pub published: Option<String>,
}
#[derive(Debug, Args)]
pub struct CalArgs {
#[arg(hide = true, trailing_var_arg = true, allow_hyphen_values = true)]
pub rest: Vec<String>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum Format {
Table,
Json,
Jsonl,
Csv,
}