use clap::{Parser, Subcommand};
use std::{io, path::PathBuf};
use wright::{
lexer::Lexer,
source_tracking::{source::Source, SourceMap, SourceRef},
};
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None, arg_required_else_help = true)]
struct Cli {
#[arg(short = 'A', long = "ascii")]
force_ascii: bool,
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand, Debug)]
enum Command {
Debug {
#[command(subcommand)]
command: DebugCommand,
},
Show {
#[command(subcommand)]
command: ShowCommand,
},
}
#[derive(Subcommand, Debug)]
enum DebugCommand {
Tokens {
file: PathBuf,
},
}
#[derive(Subcommand, Debug)]
enum ShowCommand {
Version,
Features,
}
fn main() -> io::Result<()> {
let cli: Cli = Cli::parse();
#[cfg(feature = "supports-unicode")]
{
wright::util::supports_unicode::set_force_ascii(cli.force_ascii);
}
match cli.command {
Command::Debug {
command: DebugCommand::Tokens { file },
} => {
let source_map: SourceMap = SourceMap::new();
let source_ref: SourceRef = source_map.add(Source::new_mapped_or_read(file)?);
let mut lexer: Lexer = Lexer::new(source_ref);
while let Some(token) = lexer.next_token() {
println!("{token}");
}
}
Command::Show {
command: ShowCommand::Version,
} => {
println!("wright {}", wright::build_info::PKG_VERSION);
}
Command::Show {
command: ShowCommand::Features,
} => {
for feature in wright::build_info::FEATURES {
println!("{feature}");
}
}
}
Ok(())
}