Added version to REPL
This commit is contained in:
parent
263686902b
commit
d63bedda7c
3 changed files with 87 additions and 1 deletions
64
Cargo.lock
generated
64
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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" }
|
22
src/repl.rs
22
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<String>,
|
||||
|
@ -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();
|
||||
|
|
Reference in a new issue