pub struct Repl<Context, E: Display> { /* private fields */ }
Expand description
Main REPL struct
Implementations§
source§impl<Context, E> Repl<Context, E>where
E: Display + From<Error>,
impl<Context, E> Repl<Context, E>where E: Display + From<Error>,
sourcepub fn new(context: Context) -> Self
pub fn new(context: Context) -> Self
Create a new Repl with the given context’s initial value.
Examples found in repository?
More examples
examples/custom_prompt.rs (line 22)
21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_prompt(&CustomPrompt)
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
examples/with_context.rs (line 33)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> Result<()> {
let mut repl = Repl::new(Context::default())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.use_completion(true)
.add_command(
Command::new("append", append)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Append name to end of list"),
)
.add_command(
Command::new("prepend", prepend)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Prepend name to front of list"),
);
repl.run()
}
examples/no_context.rs (line 23)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("add", add)
.with_parameter(Parameter::new("first").set_required(true)?)?
.with_parameter(Parameter::new("second").set_required(true)?)?
.with_help("Add two numbers together"),
)
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
sourcepub fn with_name(self, name: &str) -> Self
pub fn with_name(self, name: &str) -> Self
Give your Repl a name. This is used in the help summary for the Repl.
Examples found in repository?
More examples
examples/custom_prompt.rs (line 23)
21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_prompt(&CustomPrompt)
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
examples/with_context.rs (line 34)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> Result<()> {
let mut repl = Repl::new(Context::default())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.use_completion(true)
.add_command(
Command::new("append", append)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Append name to end of list"),
)
.add_command(
Command::new("prepend", prepend)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Prepend name to front of list"),
);
repl.run()
}
examples/no_context.rs (line 24)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("add", add)
.with_parameter(Parameter::new("first").set_required(true)?)?
.with_parameter(Parameter::new("second").set_required(true)?)?
.with_help("Add two numbers together"),
)
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
sourcepub fn with_version(self, version: &str) -> Self
pub fn with_version(self, version: &str) -> Self
Give your Repl a version. This is used in the help summary for the Repl.
Examples found in repository?
More examples
examples/custom_prompt.rs (line 25)
21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_prompt(&CustomPrompt)
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
examples/with_context.rs (line 35)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> Result<()> {
let mut repl = Repl::new(Context::default())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.use_completion(true)
.add_command(
Command::new("append", append)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Append name to end of list"),
)
.add_command(
Command::new("prepend", prepend)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Prepend name to front of list"),
);
repl.run()
}
examples/no_context.rs (line 25)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("add", add)
.with_parameter(Parameter::new("first").set_required(true)?)?
.with_parameter(Parameter::new("second").set_required(true)?)?
.with_help("Add two numbers together"),
)
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
sourcepub fn with_description(self, description: &str) -> Self
pub fn with_description(self, description: &str) -> Self
Give your Repl a description. This is used in the help summary for the Repl.
Examples found in repository?
More examples
examples/custom_prompt.rs (line 26)
21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_prompt(&CustomPrompt)
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
examples/with_context.rs (line 36)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> Result<()> {
let mut repl = Repl::new(Context::default())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.use_completion(true)
.add_command(
Command::new("append", append)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Append name to end of list"),
)
.add_command(
Command::new("prepend", prepend)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Prepend name to front of list"),
);
repl.run()
}
examples/no_context.rs (line 26)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("add", add)
.with_parameter(Parameter::new("first").set_required(true)?)?
.with_parameter(Parameter::new("second").set_required(true)?)?
.with_help("Add two numbers together"),
)
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
sourcepub fn with_prompt(self, prompt: &'static dyn Display) -> Self
pub fn with_prompt(self, prompt: &'static dyn Display) -> Self
Give your Repl a custom prompt. The default prompt is the Repl name, followed by
a >
, all in green, followed by a space.
Examples found in repository?
examples/custom_prompt.rs (line 24)
21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_prompt(&CustomPrompt)
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
sourcepub fn with_help_viewer<V: 'static + HelpViewer>(self, help_viewer: V) -> Self
pub fn with_help_viewer<V: 'static + HelpViewer>(self, help_viewer: V) -> Self
Pass in a custom help viewer
sourcepub fn with_error_handler(
self,
handler: fn(error: E, repl: &Repl<Context, E>) -> Result<()>
) -> Self
pub fn with_error_handler( self, handler: fn(error: E, repl: &Repl<Context, E>) -> Result<()> ) -> Self
Pass in a custom error handler. This is really only for testing - the default error handler simply prints the error to stderr and then returns
sourcepub fn use_completion(self, value: bool) -> Self
pub fn use_completion(self, value: bool) -> Self
Set whether to use command completion when tab is hit. Defaults to false.
Examples found in repository?
examples/with_context.rs (line 37)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> Result<()> {
let mut repl = Repl::new(Context::default())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.use_completion(true)
.add_command(
Command::new("append", append)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Append name to end of list"),
)
.add_command(
Command::new("prepend", prepend)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Prepend name to front of list"),
);
repl.run()
}
sourcepub fn add_command(self, command: Command<Context, E>) -> Self
pub fn add_command(self, command: Command<Context, E>) -> Self
Add a command to your REPL
Examples found in repository?
More examples
examples/custom_prompt.rs (lines 27-31)
21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_prompt(&CustomPrompt)
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
examples/with_context.rs (lines 38-42)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> Result<()> {
let mut repl = Repl::new(Context::default())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.use_completion(true)
.add_command(
Command::new("append", append)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Append name to end of list"),
)
.add_command(
Command::new("prepend", prepend)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Prepend name to front of list"),
);
repl.run()
}
examples/no_context.rs (lines 27-32)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("add", add)
.with_parameter(Parameter::new("first").set_required(true)?)?
.with_parameter(Parameter::new("second").set_required(true)?)?
.with_help("Add two numbers together"),
)
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
sourcepub fn run(&mut self) -> Result<()>
pub fn run(&mut self) -> Result<()>
Examples found in repository?
More examples
examples/custom_prompt.rs (line 32)
21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_prompt(&CustomPrompt)
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
examples/with_context.rs (line 48)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> Result<()> {
let mut repl = Repl::new(Context::default())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.use_completion(true)
.add_command(
Command::new("append", append)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Append name to end of list"),
)
.add_command(
Command::new("prepend", prepend)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Prepend name to front of list"),
);
repl.run()
}
examples/no_context.rs (line 38)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("add", add)
.with_parameter(Parameter::new("first").set_required(true)?)?
.with_parameter(Parameter::new("second").set_required(true)?)?
.with_help("Add two numbers together"),
)
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}