-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: reimplement colon command as a "simple builtin" (#315)
- Loading branch information
Showing
5 changed files
with
64 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
use clap::Parser; | ||
|
||
use crate::{builtins, commands}; | ||
use crate::{builtins, commands, error}; | ||
|
||
/// No-op command. | ||
#[derive(Parser)] | ||
#[clap(disable_help_flag = true, disable_version_flag = true)] | ||
pub(crate) struct ColonCommand { | ||
#[clap(allow_hyphen_values = true)] | ||
args: Vec<String>, | ||
} | ||
pub(crate) struct ColonCommand {} | ||
|
||
impl builtins::SimpleCommand for ColonCommand { | ||
fn get_content( | ||
_name: &str, | ||
content_type: builtins::ContentType, | ||
) -> Result<String, crate::error::Error> { | ||
match content_type { | ||
builtins::ContentType::DetailedHelp => { | ||
Ok("Null command; always returns success.".into()) | ||
} | ||
builtins::ContentType::ShortUsage => Ok(":: :".into()), | ||
builtins::ContentType::ShortDescription => Ok(": - Null command".into()), | ||
builtins::ContentType::ManPage => error::unimp("man page not yet implemented"), | ||
} | ||
} | ||
|
||
impl builtins::Command for ColonCommand { | ||
async fn execute( | ||
&self, | ||
fn execute( | ||
_context: commands::ExecutionContext<'_>, | ||
) -> Result<crate::builtins::ExitCode, crate::error::Error> { | ||
Ok(builtins::ExitCode::Success) | ||
_args: &[&str], | ||
) -> Result<builtins::BuiltinResult, crate::error::Error> { | ||
Ok(builtins::BuiltinResult { | ||
exit_code: builtins::ExitCode::Success, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters