-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathhelp.rs
More file actions
58 lines (48 loc) · 1.42 KB
/
help.rs
File metadata and controls
58 lines (48 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use regex::Regex;
fn dim(input: &str) -> String {
// Placeholder function for "dim" styling
format!("\x1b[2m{}\x1b[0m", input)
}
pub fn usage() -> String {
#[cfg(target_os = "macos")]
let open = "open";
#[cfg(windows)]
let open = "foo";
#[cfg(target_os = "linux")]
let open = "xdg-open";
let usage = r##"
usage:
pkgx [+pkg@x.y…] <program|path> [--] [arg…]
examples:
$ pkgx gum format "# hello world" "sup?"
$ pkgx node@18 --eval 'console.log("hello world")'
$ pkgx +openssl cargo build
modes:
$ pkgx --query bun # could you run `bun`? (-Q)
$ pkgx --help # hi mom!
$ pkgx --version
flags:
-q, --quiet # suppress brief informational messages
-qq, --silent # no chat. no errors. just execute.
-j, --json=v2 # output JSON (if sensible)
-C, --chdir <d> # change directory first
--sync # sync first (note: rarely if ever needed)
-v # print version and continue
more:
$ OPEN https://docs.pkgx.sh
"##;
let usage = usage
.replace('[', &dim("["))
.replace(']', &dim("]"))
.replace('<', &dim("<"))
.replace('>', &dim(">"))
.replace('$', &dim("$"))
.replace('|', &dim("|"))
.replace("OPEN", open);
let re = Regex::new("(?m) #.*$").unwrap();
re.replace_all(&usage, |caps: ®ex::Captures| {
dim(caps.get(0).unwrap().as_str())
})
.trim()
.to_string()
}