morph-cli 0.1.0

AST-based codebase migration and codemod tool for JavaScript and TypeScript projects.
Documentation
use anyhow::Result;

use crate::utils::terminal;

pub fn execute() -> Result<()> {
    let version = env!("CARGO_PKG_VERSION");
    let git_hash = env!("MORPH_CLI_GIT_HASH");
    let build_time = env!("MORPH_CLI_BUILD_TIME");

    println!("{} {}", terminal::label("morph-cli"), version);
    println!("{} {}", terminal::muted_prefix(), terminal::label("───────────────"));
    println!("  {}  {}", terminal::label("Commit:"), git_hash);
    println!("  {}  {}", terminal::label("Build: "), format_timestamp(build_time));

    Ok(())
}

fn format_timestamp(ts: &str) -> String {
    use chrono::{TimeZone, Utc};
    if let Ok(secs) = ts.parse::<i64>() {
        let dt = Utc.timestamp_opt(secs, 0).unwrap();
        dt.format("%Y-%m-%d %H:%M:%S UTC").to_string()
    } else {
        ts.to_string()
    }
}