-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.rs
More file actions
65 lines (54 loc) · 1.45 KB
/
Copy pathmain.rs
File metadata and controls
65 lines (54 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Main file runing kipt.
//!
use anyhow::Result;
use clap::Parser;
use std::fs::File;
use std::io::Read;
use tracing_subscriber::{fmt, layer::SubscriberExt, EnvFilter, Registry};
mod account;
mod args;
mod call;
mod declare;
mod deploy;
mod error;
mod invoke;
mod logger;
mod lua;
mod transaction;
const VERSION_STRING: &str = env!("CARGO_PKG_VERSION");
/// Runs main Kipt program.
fn main() -> Result<()> {
init_tracing();
let args = args::Args::parse();
if args.version {
println!("{}", VERSION_STRING);
return Ok(());
}
if let Some(lua) = &args.lua {
let program = load_file(&lua.to_string_lossy())?;
Ok(lua::execute(&program)?)
} else {
// Help will be printed out by Args.
Ok(())
}
}
/// Loads a file content as `String`.
///
/// # Arguments
///
/// * `file_path` - Path of the file to be loaded.
fn load_file(file_path: &str) -> Result<String> {
let mut file = File::open(file_path)?;
let mut file_contents = String::new();
file.read_to_string(&mut file_contents)?;
Ok(file_contents)
}
/// Initializes tracing.
fn init_tracing() {
tracing_log::LogTracer::init().expect("Setting log tracer failed.");
let env_filter = EnvFilter::from_default_env();
let fmt_layer = fmt::layer();
let subscriber = Registry::default().with(env_filter).with(fmt_layer);
tracing::subscriber::set_global_default(subscriber)
.expect("Setting default subscriber failed.");
}