Add source files: main, lib, cli, error, convert, highlight, validate, typescript
This commit is contained in:
141
src/cli.rs
Normal file
141
src/cli.rs
Normal file
@@ -0,0 +1,141 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Parser, ValueEnum};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(name = "config-forge")]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Args {
|
||||
#[arg(long, global = true)]
|
||||
pub no_color: bool,
|
||||
|
||||
#[arg(long, global = true, short = 'v')]
|
||||
pub verbose: bool,
|
||||
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
}
|
||||
|
||||
#[derive(Debug, ValueEnum, Clone)]
|
||||
pub enum OutputFormat {
|
||||
json,
|
||||
yaml,
|
||||
toml,
|
||||
env,
|
||||
ini,
|
||||
}
|
||||
|
||||
#[derive(Debug, ValueEnum, Clone)]
|
||||
pub enum SchemaSource {
|
||||
inline,
|
||||
file,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ConvertArgs {
|
||||
#[arg(short, long)]
|
||||
pub input: PathBuf,
|
||||
|
||||
#[arg(short, long, value_enum)]
|
||||
pub from: Option<OutputFormat>,
|
||||
|
||||
#[arg(short, long, value_enum)]
|
||||
pub to: OutputFormat,
|
||||
|
||||
#[arg(short, long)]
|
||||
pub output: Option<PathBuf>,
|
||||
|
||||
#[arg(long)]
|
||||
pub no_highlight: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ValidateArgs {
|
||||
#[arg(short, long)]
|
||||
pub config: PathBuf,
|
||||
|
||||
#[arg(short = 's', long = "schema", conflicts_with = "schema_file")]
|
||||
pub schema: Option<String>,
|
||||
|
||||
#[arg(short = 'S', long = "schema-file")]
|
||||
pub schema_file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct GenerateTsArgs {
|
||||
#[arg(short, long)]
|
||||
pub input: PathBuf,
|
||||
|
||||
#[arg(short, long, value_enum)]
|
||||
pub from: Option<OutputFormat>,
|
||||
|
||||
#[arg(short, long)]
|
||||
pub output: Option<PathBuf>,
|
||||
|
||||
#[arg(long)]
|
||||
pub interface_name: Option<String>,
|
||||
|
||||
#[arg(long)]
|
||||
pub export: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct BatchArgs {
|
||||
#[arg(short, long)]
|
||||
pub pattern: String,
|
||||
|
||||
#[arg(short, long, value_enum)]
|
||||
pub to: OutputFormat,
|
||||
|
||||
#[arg(short, long)]
|
||||
pub output_dir: Option<PathBuf>,
|
||||
|
||||
#[arg(long)]
|
||||
pub parallel: bool,
|
||||
|
||||
#[arg(long)]
|
||||
pub no_highlight: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct InferArgs {
|
||||
#[arg(short, long)]
|
||||
pub input: PathBuf,
|
||||
|
||||
#[arg(short, long, value_enum)]
|
||||
pub from: Option<OutputFormat>,
|
||||
|
||||
#[arg(short, long)]
|
||||
pub output: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct InitArgs {
|
||||
#[arg(short, long)]
|
||||
pub output: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub enum Command {
|
||||
#[command(name = "convert")]
|
||||
Convert(ConvertArgs),
|
||||
|
||||
#[command(name = "validate")]
|
||||
Validate(ValidateArgs),
|
||||
|
||||
#[command(name = "generate-ts")]
|
||||
GenerateTs(GenerateTsArgs),
|
||||
|
||||
#[command(name = "batch")]
|
||||
Batch(BatchArgs),
|
||||
|
||||
#[command(name = "infer")]
|
||||
Infer(InferArgs),
|
||||
|
||||
#[command(name = "init")]
|
||||
Init(InitArgs),
|
||||
}
|
||||
|
||||
pub fn parse_args() -> Args {
|
||||
Args::parse()
|
||||
}
|
||||
Reference in New Issue
Block a user