diff options
author | Canop <cano.petrole@gmail.com> | 2020-04-14 10:54:15 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-04-14 14:39:24 +0200 |
commit | 2e9fb3295d7ee797d01c1f573c15c9a7e915d9ae (patch) | |
tree | 4661c2ea4fb6cb19c753de531a41222da59d688a /src/verb/verb_execution.rs | |
parent | eef0c44dfc9a8d5ae121f9d97eee45cf494f34d2 (diff) |
focus dir in new panel with tab
The new panels feature is still a work in progress.
With this commit also comes the start of a big verb refactoring.
Diffstat (limited to 'src/verb/verb_execution.rs')
-rw-r--r-- | src/verb/verb_execution.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/verb/verb_execution.rs b/src/verb/verb_execution.rs new file mode 100644 index 0000000..928fd75 --- /dev/null +++ b/src/verb/verb_execution.rs @@ -0,0 +1,43 @@ + +use { + crate::{ + errors::ConfError, + }, + super::{ + Internal, + }, +}; + +/// how a verb must be executed, as described in the configuration +#[derive(Debug, Clone)] +pub enum VerbExecution { + + /// the verb execution is an internal or refers to another verb. + /// Executions in conf starting with ":" are of this type. + Internal { + internal: Internal, + bang: bool, + }, + + /// the verb execution refers to a command that will be executed by the system + External(String), +} + +impl VerbExecution { + pub fn try_from(mut s: &str) -> Result<Self, ConfError> { + Ok( + if s.starts_with(':') || s.starts_with(' ') { + s = &s[1..]; + let mut bang = false; + if s.starts_with('!') { + bang = true; + s = &s[1..]; + } + let internal = Internal::try_from(s)?; + Self::Internal{ internal, bang } + } else { + Self::External(s.to_string()) + } + ) + } +} |