Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 10, 2024
1 parent 42f086e commit b133d10
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ heck = "0.4.1"
default = ["clap"]

[dev-dependencies]
ctor = "0.2"
insta = "1"

[package.metadata.release]
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ xx = "0.2"

[dev-dependencies]
assert_cmd = { version = "2", features = ["color-auto"] }
ctor = "0.2"
predicates = "3"
3 changes: 3 additions & 0 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ mod errors;
mod hash;
mod shebang;

#[cfg(test)]
mod test;

pub fn run(args: &[String]) -> Result<()> {
trace!("args: {:?}", args);
// if let Some("__USAGE__") = args.get(2).map(|s| s.as_str()) {
Expand Down
6 changes: 6 additions & 0 deletions cli/src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::env;

#[ctor::ctor]
fn init() {
env::set_var("USAGE_BIN", "usage");
}
2 changes: 1 addition & 1 deletion src/complete/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod tests {
_USAGE_SPEC_MYCLI="$(mycli complete --usage)"
fi

COMPREPLY=( $(/Users/jdx/src/usage/target/debug/deps/usage-6b6342071eb3064a complete-word -s "${_USAGE_SPEC_MYCLI}" --cword="$COMP_CWORD" -- "${COMP_WORDS[@]}") )
COMPREPLY=( $(usage complete-word -s "${_USAGE_SPEC_MYCLI}" --cword="$COMP_CWORD" -- "${COMP_WORDS[@]}") )
if [[ $? -ne 0 ]]; then
unset COMPREPLY
fi
Expand Down
2 changes: 1 addition & 1 deletion src/complete/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod tests {
// let spec = Spec::parse(&Default::default(), spec).unwrap();
assert_snapshot!(complete_fish("mycli", "mycli complete --usage").trim(), @r###"
set _usage_spec_mycli (mycli complete --usage)
complete -xc mycli -a '(/Users/jdx/src/usage/target/debug/deps/usage-6b6342071eb3064a complete-word -s "$_usage_spec_mycli" --ctoken=(commandline -t) -- (commandline -op))'
complete -xc mycli -a '(usage complete-word -s "$_usage_spec_mycli" --ctoken=(commandline -t) -- (commandline -op))'
"###);
}
}
8 changes: 8 additions & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ pub static USAGE_BIN: Lazy<PathBuf> = Lazy::new(|| {
.or_else(|| current_exe().ok())
.unwrap_or_else(|| "usage".into())
});

/// On linux, env::current_exe() follows symlinks which causes problems when updating the CLI.
#[cfg(not(target_os = "macos"))]
pub static USAGE_BIN: Lazy<PathBuf> = Lazy::new(|| {
var_os("USAGE_BIN")
.map(PathBuf::from)
.unwrap_or_else(|| "usage".into())
});
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub mod context;
pub(crate) mod env;
pub mod parse;

#[cfg(test)]
mod test;

pub use crate::parse::arg::SpecArg;
pub use crate::parse::cmd::SpecCommand;
pub use crate::parse::complete::Complete;
Expand Down
6 changes: 6 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::env;

#[ctor::ctor]
fn init() {
env::set_var("USAGE_BIN", "usage");
}

0 comments on commit b133d10

Please sign in to comment.