1
//! Argument checks shared by the natives that take an entity id or a tag name.
2

            
3
use uuid::Uuid;
4

            
5
pub(super) use super::forms::args_error;
6

            
7
/// The `:label` argument, which must be present and non-empty.
8
97442
pub(super) fn required(ctx: &str, label: &str, arg: Option<String>) -> wasmtime::Result<String> {
9
97442
    arg.filter(|s| !s.is_empty())
10
192
        .ok_or_else(|| args_error(format!("{ctx}: missing or empty :{label} arg")))
11
97442
}
12

            
13
/// The `:label` argument, which must be present (it may be empty).
14
3373
pub(super) fn present<T>(ctx: &str, label: &str, arg: Option<T>) -> wasmtime::Result<T> {
15
3373
    arg.ok_or_else(|| args_error(format!("{ctx}: missing :{label} arg")))
16
3373
}
17

            
18
/// The `:label` argument parsed as a UUID.
19
17374
pub(super) fn uuid_arg(ctx: &str, label: &str, arg: Option<String>) -> wasmtime::Result<Uuid> {
20
17374
    let raw = required(ctx, label, arg)?;
21
17204
    Uuid::parse_str(&raw).map_err(|err| args_error(format!("{ctx}: invalid uuid '{raw}': {err}")))
22
17374
}
23

            
24
/// The `:tag-name` argument, which must be non-empty.
25
3540
pub(super) fn tag_name_arg(ctx: &str, arg: Option<String>) -> wasmtime::Result<String> {
26
3540
    required(ctx, "tag-name", arg)
27
3540
}