mirror of
https://github.com/nushell/nushell.git
synced 2024-12-11 09:43:24 +01:00
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
mod char_;
|
|
mod detect_columns;
|
|
mod encode_decode;
|
|
mod format;
|
|
mod parse;
|
|
mod size;
|
|
mod split;
|
|
mod str_;
|
|
|
|
pub use char_::Char;
|
|
pub use detect_columns::*;
|
|
pub use encode_decode::*;
|
|
pub use format::*;
|
|
pub use parse::*;
|
|
pub use size::Size;
|
|
pub use split::*;
|
|
pub use str_::*;
|
|
|
|
use nu_protocol::{ast::Call, ShellError};
|
|
|
|
// For handling the grapheme_cluster related flags on some commands.
|
|
// This ensures the error messages are consistent.
|
|
pub fn grapheme_flags(call: &Call) -> Result<bool, ShellError> {
|
|
let g_flag = call.has_flag("grapheme-clusters");
|
|
// Check for the other flags and produce errors if they exist.
|
|
// Note that Nushell already prevents nonexistant flags from being used with commands,
|
|
// so this function can be reused for both the --utf-8-bytes commands and the --code-points commands.
|
|
if g_flag && call.has_flag("utf-8-bytes") {
|
|
Err(ShellError::IncompatibleParametersSingle(
|
|
"Incompatible flags: --grapheme-clusters (-g) and --utf-8-bytes (-b)".to_string(),
|
|
call.head,
|
|
))?
|
|
}
|
|
if g_flag && call.has_flag("code-points") {
|
|
Err(ShellError::IncompatibleParametersSingle(
|
|
"Incompatible flags: --grapheme-clusters (-g) and --utf-8-bytes (-b)".to_string(),
|
|
call.head,
|
|
))?
|
|
}
|
|
// Grapheme cluster usage is decided by the non-default -g flag
|
|
Ok(g_flag)
|
|
}
|