Use required-features for bin tools.

This commit is contained in:
Stephen Chung
2022-01-30 09:41:51 +08:00
parent 2cfd426aaf
commit 0378c822e1
3 changed files with 50 additions and 68 deletions

View File

@@ -3,10 +3,38 @@ Rhai Tools
Tools for running Rhai scripts.
| Tool | Required feature(s) | Description |
| -------------------------------------------------------------------------------- | :-----------------: | --------------------------------------------------- |
| [`rhai-run`](https://github.com/rhaiscript/rhai/blob/main/src/bin/rhai-run.rs) | | runs each filename passed to it as a Rhai script |
| [`rhai-repl`](https://github.com/rhaiscript/rhai/blob/main/src/bin/rhai-repl.rs) | `rustyline` | simple REPL that interactively evaluates statements |
| [`rhai-dbg`](https://github.com/rhaiscript/rhai/blob/main/src/bin/rhai-dbg.rs) | `debugging` | the _Rhai Debugger_ |
How to Run
----------
```bash
```sh
cargo run --bin sample_app_to_run
```
or with required features
```sh
cargo run --bin sample_app_to_run --features feature1,feature2,feature3
```
How to Install
--------------
To install these all tools (with [`decimal`] and [`metadata`] support), use the following command:
```sh
cargo install --path . --bins --features decimal,metadata,debugging,rustyline
```
or specifically:
```sh
cargo install --path . --bin rhai-run --features decimal,metadata,debugging,rustyline
```

View File

@@ -1,12 +1,6 @@
#![cfg(not(feature = "no_std"))]
#[cfg(feature = "debugging")]
use rhai::debugger::DebuggerCommand;
use rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, Position, Scope};
#[cfg(feature = "debugging")]
use rhai::debugger::DebuggerCommand;
#[cfg(feature = "debugging")]
use std::{
env,
fs::File,
@@ -16,7 +10,6 @@ use std::{
};
/// Pretty-print source line.
#[cfg(feature = "debugging")]
fn print_source(lines: &[String], pos: Position, offset: usize) {
let line_no = if lines.len() > 1 {
if pos.is_none() {
@@ -44,7 +37,6 @@ fn print_source(lines: &[String], pos: Position, offset: usize) {
}
/// Pretty-print error.
#[cfg(feature = "debugging")]
fn print_error(input: &str, mut err: EvalAltResult) {
let lines: Vec<_> = input.trim().split('\n').collect();
let pos = err.take_position();
@@ -78,7 +70,6 @@ fn print_error(input: &str, mut err: EvalAltResult) {
}
/// Print debug help.
#[cfg(feature = "debugging")]
fn print_debug_help() {
println!("help => print this help");
println!("quit, exit, kill => quit");
@@ -114,7 +105,6 @@ fn print_debug_help() {
}
/// Display the scope.
#[cfg(feature = "debugging")]
fn print_scope(scope: &Scope, dedup: bool) {
let flattened_clone;
let scope = if dedup {
@@ -153,7 +143,6 @@ fn print_scope(scope: &Scope, dedup: bool) {
println!();
}
#[cfg(feature = "debugging")]
fn main() {
let title = format!("Rhai Debugger (version {})", env!("CARGO_PKG_VERSION"));
println!("{}", title);
@@ -552,8 +541,3 @@ fn main() {
}
}
}
#[cfg(not(feature = "debugging"))]
fn main() {
panic!("rhai-dbg requires the 'debugging' feature.")
}