1pub mod script;
2pub mod shell;
3pub mod value;
4
5pub(crate) use aopt_core as acore;
6
7pub(crate) const SHELL_BASH: &str = "bash";
8pub(crate) const SHELL_FISH: &str = "fish";
9pub(crate) const SHELL_ZSH: &str = "zsh";
10pub(crate) const SHELL_PSH: &str = "powershell";
11
12pub use acore::error;
13pub use acore::failure;
14
15use std::borrow::Cow;
16use std::ffi::OsStr;
17use std::ffi::OsString;
18
19pub(crate) use acore::Error;
20
21pub struct Context<'a> {
22 pub args: &'a [OsString],
23
24 pub arg: Cow<'a, OsStr>,
26
27 pub val: Option<Cow<'a, OsStr>>,
29
30 pub prev: Cow<'a, OsStr>,
32}
33
34impl<'a> Context<'a> {
35 pub fn new(args: &'a [OsString], curr: &'a OsString, prev: &'a OsString) -> Self {
36 use std::borrow::Cow;
37
38 let mut incomplete_arg = Cow::Borrowed(curr.as_ref());
39 let mut incomplete_val = None;
40
41 if let Some((opt, val)) = aopt_core::str::split_once(curr, '=') {
42 incomplete_arg = opt;
43 incomplete_val = Some(val);
44 }
45
46 Self {
47 args,
48 arg: incomplete_arg,
49 val: incomplete_val,
50 prev: std::borrow::Cow::Borrowed(prev),
51 }
52 }
53}