2021-12-16 00:08:12 +01:00
|
|
|
mod char_;
|
2022-01-30 13:52:24 +01:00
|
|
|
mod detect_columns;
|
2022-06-25 23:35:23 +02:00
|
|
|
mod encode_decode;
|
2021-11-15 19:27:15 +01:00
|
|
|
mod parse;
|
2021-10-12 23:55:29 +02:00
|
|
|
mod size;
|
2021-10-09 03:02:01 +02:00
|
|
|
mod split;
|
2021-11-06 18:55:25 +01:00
|
|
|
mod str_;
|
2021-09-29 20:25:05 +02:00
|
|
|
|
2021-12-16 00:08:12 +01:00
|
|
|
pub use char_::Char;
|
2022-01-30 13:52:24 +01:00
|
|
|
pub use detect_columns::*;
|
2022-06-25 23:35:23 +02:00
|
|
|
pub use encode_decode::*;
|
2021-11-15 19:27:15 +01:00
|
|
|
pub use parse::*;
|
2021-10-12 23:55:29 +02:00
|
|
|
pub use size::Size;
|
2021-10-09 03:02:01 +02:00
|
|
|
pub use split::*;
|
2021-11-06 18:55:25 +01:00
|
|
|
pub use str_::*;
|
2023-01-20 08:16:18 +01:00
|
|
|
|
|
|
|
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.
|
2023-01-28 22:22:56 +01:00
|
|
|
// Note that Nushell already prevents nonexistent flags from being used with commands,
|
2023-01-20 08:16:18 +01:00
|
|
|
// 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") {
|
2023-03-06 11:31:07 +01:00
|
|
|
Err(ShellError::IncompatibleParametersSingle {
|
|
|
|
msg: "Incompatible flags: --grapheme-clusters (-g) and --utf-8-bytes (-b)".to_string(),
|
|
|
|
span: call.head,
|
|
|
|
})?
|
2023-01-20 08:16:18 +01:00
|
|
|
}
|
|
|
|
if g_flag && call.has_flag("code-points") {
|
2023-03-06 11:31:07 +01:00
|
|
|
Err(ShellError::IncompatibleParametersSingle {
|
|
|
|
msg: "Incompatible flags: --grapheme-clusters (-g) and --utf-8-bytes (-b)".to_string(),
|
|
|
|
span: call.head,
|
|
|
|
})?
|
2023-01-20 08:16:18 +01:00
|
|
|
}
|
|
|
|
// Grapheme cluster usage is decided by the non-default -g flag
|
|
|
|
Ok(g_flag)
|
|
|
|
}
|