From d63bedda7c9197e23e24f5340f6f80a2a4981296 Mon Sep 17 00:00:00 2001 From: Anthony Foxclaw <35226681+tonytins@users.noreply.github.com> Date: Fri, 7 Feb 2020 00:02:43 -0500 Subject: [PATCH] Added version to REPL --- Cargo.lock | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/repl.rs | 22 +++++++++++++++++- 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ffe0633..5307978 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,3 +3,67 @@ [[package]] name = "corten" version = "0.1.0" +dependencies = [ + "metacrate", + "rbtag", +] + +[[package]] +name = "metacrate" +version = "0.1.0" +source = "git+https://github.com/tonytins/metacrate#efab304454bd48946d52efa0912b65898f37b1c9" + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rbtag" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c64936fcc0b811890a9d90020f3df5cec9c604efde88af7db6a35d365132a3" +dependencies = [ + "rbtag_derive", +] + +[[package]] +name = "rbtag_derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b75511b710ccca8adbb211e04763bd8c78fed585b0ec188a20ed9b0dd95567c4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" diff --git a/Cargo.toml b/Cargo.toml index 2c0b105..f65c093 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +rbtag = "0.3" +metacrate = { git = "https://github.com/tonytins/metacrate" } \ No newline at end of file diff --git a/src/repl.rs b/src/repl.rs index fe470ca..b85c0c6 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -4,6 +4,21 @@ use std::num::ParseIntError; use std::io::Write; use crate::vm::VM; +use metacrate::crate_version; +use rbtag::{BuildDateTime, BuildInfo}; + +#[derive(BuildDateTime, BuildInfo)] +struct BuildTag; + +/// Remove "-clean" from the commit id +fn normalize_commit_id(id: &str) -> String { + let clean_stat = "-clean"; + + match id.contains(clean_stat) { + true => id.replace(clean_stat, ""), + false => id.to_string(), + } +} pub struct REPL { command_buffer: Vec, @@ -21,7 +36,12 @@ impl REPL { /// Runs a similar VM execution loop but the instructions are taken from /// the user directly at the terminal and not from pre-compiled byte code pub fn run(&mut self) { - println!("Welcome to the Corten REPL"); + let ver_id = format!( + "{}+{}", + crate_version!(), + normalize_commit_id(BuildTag {}.get_build_commit()) + ); + println!("Corten {}", ver_id); loop { // Allocates a new string in which to store the user types each iteration let mut buffer = String::new();