use std::cmp::PartialEq;
use clap::CommandFactory;
use clap::{Parser, Subcommand};
use orn_cli::const_values::get_constant_values;
use orn_cli::file_manager::FileManager;
use orn_cli::gen_const::gen_consts;
use orn_cli::update_notifier::check_latest_version;
#[derive(Parser, Debug)]
#[command(name = "orn")]
#[command(about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
#[clap(short, long)]
version: bool,
}
#[derive(Subcommand, Clone, Debug, PartialEq)]
enum Commands {
Version,
UpdateConst {
#[arg(short, long = "path", default_value = "**/*.move")]
paths: Vec<String>,
},
}
#[tokio::main]
async fn main() {
if !check_latest_version(
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
"https://crates.io"
).unwrap() {
return;
}
let args = Cli::parse();
if args.version {
println!(env!("APP_VERSION"));
return;
}
match args.command {
Some(command) => match command {
Commands::Version => {
println!(env!("APP_VERSION"));
return;
}
Commands::UpdateConst { paths } => {
update_const(&paths).await;
return;
}
},
None => {
Cli::command().print_help().unwrap();
return;
}
}
}
async fn update_const(paths: &Vec<String>) {
let constant_values = get_constant_values();
let file_manager = FileManager::load(paths).unwrap();
file_manager
.update(|file_content| gen_consts(&file_content, &constant_values))
.unwrap()
}