alux_cli/argument.rs
1/// States how many occurrences an argument takes, as its source's shape says.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum Arity {
4 /// Exactly one value.
5 One,
6 /// At most one value: `Option` of it.
7 Optional,
8 /// Any number of values, in order: `Vec` of them.
9 Many,
10 /// No value; whether it occurs: `bool`.
11 Presence,
12 /// A value written only in the option's own word, or none: `-i`, `-i.bak`, `--in-place=.bak`.
13 /// `Option<Option<_>>`: whether it occurs, and the value it was given.
14 OptionalValue,
15}
16
17/// Decodes one word as a value; an interpreter answers it for the values it supports.
18pub trait CliWordAlg<Value, Word: ?Sized> {
19 /// Why a word does not denote a value.
20 type Error;
21
22 /// Decodes `word` as a value.
23 ///
24 /// # Errors
25 ///
26 /// Answers with the interpreter's error when `word` does not denote a value.
27 fn cli_word(&self, word: &Word) -> Result<Value, Self::Error>;
28}
29
30/// States why the words given for an argument do not make its value.
31#[derive(Clone, Debug, PartialEq, Eq)]
32pub enum CliArgumentError<Error> {
33 /// An argument of arity one was not given.
34 Missing(&'static str),
35 /// An argument taking at most one value was given more than once.
36 Repeated(&'static str),
37 /// A word did not decode as the argument's value.
38 Word(&'static str, Error),
39 /// Two alternatives of a sum were given together.
40 Conflict(&'static str, &'static str),
41}