-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Basic support for Darwin (#17)
* Update Cargo.lock * Port Fish's Darwin parser * Rename darwin_bless test to darwin_bless_json * fix: Fix quote replacement
- Loading branch information
Showing
11 changed files
with
5,668 additions
and
277 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use regex::{Regex, RegexBuilder}; | ||
|
||
use super::util; | ||
use crate::Flag; | ||
|
||
/// For parsing Darwin man pages (ported from Fish) | ||
#[allow( | ||
clippy::case_sensitive_file_extension_comparisons, | ||
clippy::doc_markdown | ||
)] | ||
pub fn parse(cmd_name: &str, page_text: &str) -> Vec<Flag> { | ||
let Some(start_ind) = page_text.find(".Sh DESCRIPTION") else { | ||
return Vec::new(); | ||
}; | ||
|
||
let mut flags = Vec::new(); | ||
|
||
// Can't use util::get_section because we also want sections after DESCRIPTION | ||
let content = &page_text[start_ind..]; | ||
|
||
// Replace '.It Fl' and the like with '.It -' (`Fl` is a dash) | ||
let fl_re = Regex::new(r"(\...) Fl ").expect("Regex should be valid"); | ||
let content = fl_re.replace_all(content, "$1 -").replace(".Fl ", "-"); | ||
|
||
let desc_end = RegexBuilder::new(r"\n\.El.*+") | ||
.dot_matches_new_line(true) | ||
.build() | ||
.expect("Regex should be valid"); | ||
|
||
let mut paras = content.split(".It"); | ||
paras.next(); // Discard the part before the first option | ||
for para in paras { | ||
let mut pieces = para.splitn(2, '\n'); | ||
if let Some(options) = pieces.next() { | ||
let desc = pieces.next().map(|desc| { | ||
let desc = desc.replace(".Nm", cmd_name); | ||
desc_end.replace(&desc, "").to_string() | ||
}); | ||
if let Some(flag) = util::make_flag(options, desc.as_deref()) { | ||
flags.push(flag); | ||
} | ||
} | ||
} | ||
|
||
flags | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.