schemaui_cli/
cli.rs

1use std::path::PathBuf;
2
3use clap::{ArgAction, Parser, Subcommand};
4
5#[cfg(feature = "web")]
6use std::net::IpAddr;
7
8#[derive(Debug, Parser)]
9#[command(
10    name = "schemaui",
11    version,
12    about = "Render JSON Schemas as interactive TUIs or Web UIs"
13)]
14pub struct Cli {
15    #[command(flatten)]
16    pub common: CommonArgs,
17
18    #[command(subcommand)]
19    pub command: Option<Commands>,
20}
21
22#[derive(Debug, Subcommand)]
23pub enum Commands {
24    /// Launch the interactive terminal UI
25    Tui,
26
27    #[cfg(feature = "web")]
28    /// Launch the interactive web UI instead of the terminal UI
29    Web(WebCommand),
30}
31
32#[cfg(feature = "web")]
33#[derive(Debug, Parser, Clone)]
34pub struct WebCommand {
35    #[command(flatten)]
36    pub common: CommonArgs,
37
38    /// Bind address for the temporary HTTP server
39    #[rustfmt::skip]
40    #[arg(alias = "bind", alias = "listen")]
41    #[arg( short = 'l', long = "host", value_name = "IP", default_value = "127.0.0.1" )]
42    pub host: IpAddr,
43
44    /// Bind port for the temporary HTTP server (0 picks a random free port)
45    #[arg(short = 'p', long = "port", value_name = "PORT", default_value_t = 0)]
46    pub port: u16,
47}
48
49#[derive(Debug, Parser, Clone)]
50pub struct CommonArgs {
51    /// Schema spec: file path, inline payload, or "-" for stdin
52    #[arg(short = 's', long = "schema", value_name = "SPEC")]
53    pub schema: Option<String>,
54
55    /// Config spec: file path, inline payload, or "-" for stdin
56    #[arg(short = 'c', long = "config", alias = "data", value_name = "SPEC")]
57    pub config: Option<String>,
58
59    /// Title shown at the top of the UI
60    #[arg(long = "title", value_name = "TEXT")]
61    pub title: Option<String>,
62
63    /// Output destinations ("-" writes to stdout). Accepts multiple values per flag use.
64    #[arg(short = 'o', long = "output", value_name = "DEST", num_args = 1.., action = ArgAction::Append)]
65    pub outputs: Vec<String>,
66
67    /// Override the default temp file location (only used when no other destinations are set)
68    #[arg(long = "temp-file", value_name = "PATH")]
69    pub temp_file: Option<PathBuf>,
70
71    /// Disable writing to the default temp file when no destinations are provided
72    #[arg(long = "no-temp-file")]
73    pub no_temp_file: bool,
74
75    /// Emit compact JSON/TOML rather than pretty formatting
76    #[arg(long = "no-pretty")]
77    pub no_pretty: bool,
78
79    /// Overwrite output files even if they already exist
80    #[arg(short = 'f', long = "force", short_alias = 'y', alias = "yes")]
81    pub force: bool,
82}