Skip to content

Commit ffb8977

Browse files
Profpatschclaude
andcommitted
pkgs/profpatsch/nman: ✨ fix dotted attribute path parsing for page names
When using dotted attribute paths like `pkgs.profpatsch.nman`, nman was incorrectly trying to find a man page named "pkgs.profpatsch.nman" instead of extracting the actual page name "nman" from the last component. Changes: - Add extract_page_name_from_attr() helper that splits on '.' and returns last component - Update CLI parsing to use helper for auto-detected page names (cases 2 and 3 args) - Add comprehensive test coverage for the helper function - Maintain backward compatibility for simple attribute names and explicit page names - Add description to the man page Now `nman --local pkgs.profpatsch.nman` correctly builds the full attribute but searches for the "nman" man page instead of "pkgs.profpatsch.nman". 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent fecb29f commit ffb8977

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

pkgs/profpatsch/nman/nman.1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ of
3636
and searches all its outputs for a man page named
3737
.Ar ATTR
3838
which may be in any section.
39+
For dotted attribute paths like
40+
.Ql pkgs.profpatsch.nman ,
41+
only the last component
42+
.Po Ql nman Pc
43+
is used as the man page name to search for.
3944
If multiple matches are found, the one that is alphanumerically
4045
lower is preferred:
4146
For example,
@@ -47,6 +52,7 @@ Like above, but
4752
.Nm
4853
will only look for the man page in the given section
4954
.Ar SECTION .
55+
For dotted attributes, the last component is used as the page name to search for.
5056
Note that
5157
.Ar SECTION
5258
must be a number or
@@ -108,6 +114,9 @@ nman mandoc 7 man
108114
# open lowdown(1) from local default.nix
109115
nman --local lowdown
110116

117+
# open nman(1) from dotted attribute path (searches for "nman", not "pkgs.profpatsch.nman")
118+
nman --local pkgs.profpatsch.nman
119+
111120
# open man page from a custom package set
112121
nman -l myCustomPackage
113122
.Ed

pkgs/profpatsch/nman/nman.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ fn main() {
2626
std::env::args().partition(|s| s.starts_with("-"));
2727

2828
let mut cli_res: CliResult = match args.len() {
29-
2 => Action(CliAction::Man(&args[1], None, &args[1])),
29+
2 => Action(CliAction::Man(&args[1], None, extract_page_name_from_attr(&args[1]))),
3030
3 => match parse_man_section(&args[2]) {
31-
Ok(s) => Action(CliAction::Man(&args[1], Some(s), &args[1])),
31+
Ok(s) => Action(CliAction::Man(&args[1], Some(s), extract_page_name_from_attr(&args[1]))),
3232
Err(_) => Action(CliAction::Man(&args[1], None, &args[2])),
3333
},
3434
4 => match parse_man_section(&args[2]) {
@@ -616,6 +616,13 @@ fn match_man_page_file(name: &str, section: &str, page: &str) -> bool {
616616
}
617617
}
618618

619+
/// Extract the page name from a dotted attribute path.
620+
/// For example, "pkgs.profpatsch.nman" becomes "nman".
621+
/// If there are no dots, returns the original string.
622+
fn extract_page_name_from_attr(attr: &str) -> &str {
623+
attr.split('.').last().unwrap_or(attr)
624+
}
625+
619626
/// Check if a string describes a man section,
620627
/// i. e. is a number or "3p" (Perl Developer's
621628
/// manual). Used to distinguish between man pages
@@ -706,6 +713,24 @@ mod tests {
706713
assert!(parse_man_section("").is_err());
707714
}
708715

716+
#[test]
717+
fn test_extract_page_name_from_attr() {
718+
// Simple case without dots
719+
assert_eq!(extract_page_name_from_attr("nman"), "nman");
720+
assert_eq!(extract_page_name_from_attr("hello"), "hello");
721+
722+
// Dotted attribute paths
723+
assert_eq!(extract_page_name_from_attr("pkgs.profpatsch.nman"), "nman");
724+
assert_eq!(extract_page_name_from_attr("a.b.c.d"), "d");
725+
assert_eq!(extract_page_name_from_attr("nixpkgs.hello"), "hello");
726+
727+
// Edge cases
728+
assert_eq!(extract_page_name_from_attr(""), "");
729+
assert_eq!(extract_page_name_from_attr("."), "");
730+
assert_eq!(extract_page_name_from_attr("package."), "");
731+
assert_eq!(extract_page_name_from_attr(".package"), "package");
732+
}
733+
709734
#[test]
710735
fn test_output_preference() {
711736
// lower =^= preferred

0 commit comments

Comments
 (0)