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
// Copyright (c) Sean Lawlor
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

//! Represents a processor of REPL commands from a user's Clap parsed input

use anyhow::Result;

#[cfg(feature = "async")]
#[cfg_attr(feature = "async", async_trait::async_trait)]
pub trait ReplCommandProcessor<C>: std::fmt::Debug
where
    C: clap::Parser,
{
    /// Process the supplied command which is a clap::Parser structure
    async fn process_command(&self, command: C) -> Result<()>;

    /// Determine if the supplied command is a "quit" operation. This will be
    /// formatted into a trimmed string of lowercase letters. Example matching might
    /// check (in English)
    ///
    /// ```
    /// fn is_quit(command: &str) -> bool {
    ///  matches!(command, "quit" | "exit")
    /// }
    /// ```
    fn is_quit(&self, command: &str) -> bool;
}

#[cfg(not(feature = "async"))]
pub trait ReplCommandProcessor<C>: std::fmt::Debug
where
    C: clap::Parser,
{
    /// Process the supplied command which is a clap::Parser structure
    fn process_command(&self, command: C) -> Result<()>;

    /// Determine if the supplied command is a "quit" operation. This will be
    /// formatted into a trimmed string of lowercase letters. Example matching might
    /// check (in English)
    ///
    /// ```
    /// fn is_quit(command: &str) -> bool {
    ///  matches!(command, "quit" | "exit")
    /// }
    /// ```
    fn is_quit(&self, command: &str) -> bool;
}