pub fn parse_hook(args: &[OsString]) -> Option<Hook>Expand description
Recognizes the hook commands. Returns None for everything else, which then goes to clap.
The new cd-hook forms are pre and post with exactly the two directories and a -- before
the cd arguments (cd-hook pre <pwd> <prev> -- <cd args...>). Anything else after cd-hook
is the legacy form: at most [TARGET] [PWD], or --post-move [PWD]. So a legacy hook for
cd pre (cd-hook pre /some/dir) is not mistaken for the new pre form.
use std::ffi::OsString;
use shellgame::cli::{Hook, parse_hook};
let args: Vec<OsString> = ["cd-hook", "pre", "/a", "", "--", "-P", "--", "x"]
.iter().map(OsString::from).collect();
let Some(Hook::CdPre { pwd, prev, args }) = parse_hook(&args) else { unreachable!() };
assert_eq!(pwd, "/a");
assert_eq!(prev, "");
assert_eq!(args, ["-P", "--", "x"]);