-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
123 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
use crate::{env, Spec}; | ||
use crate::env; | ||
|
||
pub fn complete_fish(spec: &Spec) -> String { | ||
let usage = &*env::USAGE_CMD; | ||
let bin = &spec.bin; | ||
let raw = spec.to_string().replace('\'', r"\'").to_string(); | ||
pub fn complete_fish(bin: &str, usage_cmd: &str) -> String { | ||
let usage = env::USAGE_BIN.display(); | ||
// let bin = &spec.bin; | ||
// let raw = spec.to_string().replace('\'', r"\'").to_string(); | ||
format!( | ||
r#" | ||
set _usage_spec_{bin} '{raw}' | ||
set _usage_spec_{bin} ({usage_cmd}) | ||
complete -xc {bin} -a '({usage} complete-word -s "$_usage_spec_{bin}" --ctoken=(commandline -t) -- (commandline -op))' | ||
"# | ||
) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::parse::spec::Spec; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_complete_fish() { | ||
let spec = r#" | ||
"#; | ||
let spec = Spec::parse(&Default::default(), spec).unwrap(); | ||
assert_snapshot!(complete_fish(&spec).trim(), @r###" | ||
set _usage_spec_ '' | ||
complete -xc -a '(usage complete-word -s "$_usage_spec_" --ctoken=(commandline -t) -- (commandline -op))' | ||
// let spec = r#" | ||
// "#; | ||
// 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))' | ||
"###); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
pub use std::env::*; | ||
use std::path::PathBuf; | ||
|
||
use once_cell::sync::Lazy; | ||
|
||
pub static USAGE_CMD: Lazy<String> = | ||
Lazy::new(|| var("USAGE_CMD").unwrap_or_else(|_| "usage".to_string())); | ||
#[cfg(target_os = "macos")] | ||
pub static USAGE_BIN: Lazy<PathBuf> = Lazy::new(|| { | ||
var_os("USAGE_BIN") | ||
.map(PathBuf::from) | ||
.or_else(|| current_exe().ok()) | ||
.unwrap_or_else(|| "usage".into()) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.