ornn 0.1.3

Gen const for smart contract
Documentation
use std::cmp::PartialEq;
use std::time::Duration;

use clap::CommandFactory;
use clap::{Parser, Subcommand};
use ornn::const_values::get_constant_values;
use ornn::file_manager::FileManager;
use ornn::gen_const::gen_consts;
use ornn::update_notifier::check_version;

/// ORN.
#[derive(Parser, Debug)]
#[command(about, long_about = None)]
struct Cli {
    #[command(subcommand)]
    command: Option<Commands>,
    #[clap(short, long)]
    version: bool,
}
#[derive(Subcommand, Clone, Debug, PartialEq)]
enum Commands {
    /// Print current version
    Version,
    /// Update constant values in Move files
    UpdateConst {
        /// File paths, can be used multiple times, accept glob patterns
        #[arg(short, long = "path", default_value = "**/*.move")]
        paths: Vec<String>,
    },
}

#[tokio::main]
async fn main() {
    // Will notify users in one day intervals if an update is available
    check_version(
        env!("CARGO_PKG_NAME"),
        env!("CARGO_PKG_VERSION"),
        Duration::from_secs(60 * 60 * 24),
    )
    .ok();

    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()
}