Rust library for loading toml configuration files from standard unix hierarchy paths
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add attribute for hiding fields and enum variants

+176 -3
+5 -1
CHANGELOG.md
··· 1 - ## [0.4.1] - 2026-01-05 1 + ## [0.5.0] - 2026-01-05 2 + 3 + ### 🚀 Features 4 + 5 + - Add attribute for hiding fields and enum variants 2 6 3 7 ### 🚜 Refactor 4 8
+21
crates/hierconf-core/src/attrs.rs
··· 53 53 /// 54 54 /// Usage: `#[facet(hierconf::type_doc("Custom documentation for this type."))]` 55 55 TypeDoc(&'static str), 56 + 57 + /// Hide a struct field or enum variant from man page generation. 58 + /// 59 + /// Usage: `#[facet(hierconf::hide)]` 60 + Hide, 56 61 } 57 62 } 58 63 ··· 88 93 } 89 94 } 90 95 96 + #[cfg(feature = "mangen")] 97 + fn has_attr(attrs: &[FacetAttr], key: &'static str) -> bool { 98 + attrs 99 + .iter() 100 + .any(|attr| attr.ns == Some("hierconf") && attr.key == key) 101 + } 102 + 91 103 /// Extract the application name from a facet type's attributes. 92 104 /// 93 105 /// Looks for `#[facet(hierconf::app_name("..."))]` attributes on the struct. ··· 140 152 pub fn extract_type_doc(attrs: &[FacetAttr]) -> Result<Option<&'static str>, HierConfError> { 141 153 Ok(get_attr_opt::<&str>(attrs, "type_doc")?.cloned()) 142 154 } 155 + 156 + /// Check if an item (field or variant) should be hidden from man page generation. 157 + /// 158 + /// Looks for `#[facet(hierconf::hide)]` attributes. 159 + /// Returns `true` if the attribute is present, `false` otherwise. 160 + #[cfg(feature = "mangen")] 161 + pub fn is_hidden(attrs: &[FacetAttr]) -> bool { 162 + has_attr(attrs, "hide") 163 + }
+1 -1
crates/hierconf-core/src/lib.rs
··· 4 4 5 5 pub use attrs::{Attr as HierConfAttr, extract_app_name}; 6 6 #[cfg(feature = "mangen")] 7 - pub use attrs::{extract_date, extract_synopsis, extract_type_doc, extract_type_name}; 7 + pub use attrs::{extract_date, extract_synopsis, extract_type_doc, extract_type_name, is_hidden}; 8 8 pub use error::HierConfError; 9 9 pub use loader::config_paths; 10 10
+4 -1
crates/hierconf-mangen/src/description/data.rs
··· 5 5 //! 2. Rendering: Generate man pages using only these structures 6 6 7 7 use facet::{Def, Shape, StructKind, Type, UserType}; 8 - use hierconf_core::{HierConfError, extract_type_doc, extract_type_name}; 8 + use hierconf_core::{HierConfError, extract_type_doc, extract_type_name, is_hidden}; 9 9 use std::collections::HashMap; 10 10 use std::convert::TryFrom; 11 11 ··· 125 125 fn fields_to_struct_fields(fields: &'static [facet::Field]) -> Result<Vec<Field>, HierConfError> { 126 126 fields 127 127 .iter() 128 + .filter(|field| !is_hidden(field.attributes)) 128 129 .map(|field| { 129 130 let name = field.name.to_string(); 130 131 let doc = doc_to_string(field.doc); ··· 145 146 fn fields_to_tuple_fields(fields: &'static [facet::Field]) -> Result<Vec<TypeRef>, HierConfError> { 146 147 fields 147 148 .iter() 149 + .filter(|field| !is_hidden(field.attributes)) 148 150 .map(|field| { 149 151 // Check for type_name override on the field 150 152 if let Some(type_name_override) = extract_type_name(field.attributes)? { ··· 190 192 let variants: Result<Vec<Variant>, HierConfError> = enum_type 191 193 .variants 192 194 .iter() 195 + .filter(|variant| !is_hidden(variant.attributes)) 193 196 .map(|variant| { 194 197 let name = variant.name.to_string(); 195 198 let doc = doc_to_string(variant.doc);
+57
crates/hierconf-mangen/tests/hide_attribute/enum.roff
··· 1 + .ie \n(.g .ds Aq \(aq 2 + .el .ds Aq ' 3 + .TH HIDETEST 5 2025-01-15 hierconf 4 + .SH NAME 5 + hidetest \- configuration file format 6 + .SH SYNOPSIS 7 + Configuration documentation. 8 + .PP 9 + See \fBDESCRIPTION\fR for configuration parameters and \fBFILES\fR for configuration file locations. 10 + .SH DESCRIPTION 11 + The \fIhidetest\fR configuration file uses the TOML format. 12 + 13 + Configuration files are checked in order of precedence, and the first file that exists is loaded. See the \fBFILES\fR section for details. 14 + 15 + .SS "Configuration structure" 16 + .TP 17 + \fBtest_enum\fR (\fITestEnum\fR) 18 + Enum field. 19 + 20 + See the \fBTypes\fR subsection for details on the \fITestEnum\fR type. 21 + 22 + .SS Types 23 + The following types are used in the configuration file: 24 + 25 + .TP 26 + \fBTestEnum\fR 27 + Test enum with hidden variant. 28 + 29 + Variants: 30 + 31 + .RS 4 32 + .IP \(bu 3 33 + \fBVisible\fR 34 + .RS 4 35 + This variant should be visible. 36 + .RE 37 + .IP \(bu 3 38 + \fBAnotherVisible\fR 39 + .RS 4 40 + Another visible variant. 41 + .RE 42 + .RE 43 + 44 + .SH FILES 45 + Configuration files are checked in the following order of precedence (highest to lowest). The first file that exists is loaded. 46 + 47 + .TP 48 + \fBtests/hidetest/config.toml\fR 49 + Test\-specific configuration file. 50 + 51 + .TP 52 + \fB/etc/hidetest/config.toml\fR 53 + System\-wide configuration file. 54 + 55 + .TP 56 + \fB/usr/share/etc/hidetest/config.toml\fR 57 + Distribution\-provided defaults.
+51
crates/hierconf-mangen/tests/hide_attribute/main.rs
··· 1 + use facet::Facet; 2 + use hierconf_core as hierconf; 3 + use hierconf_mangen::generate_man_page; 4 + 5 + #[derive(Facet)] 6 + #[facet(hierconf::app_name("hidetest"))] 7 + #[facet(hierconf::date("2025-01-15"))] 8 + struct TestConfig { 9 + /// This field should be visible. 10 + visible_field: String, 11 + /// This field should be hidden. 12 + #[facet(hierconf::hide)] 13 + hidden_field: String, 14 + /// Another visible field. 15 + another_visible: u16, 16 + } 17 + 18 + /// Test enum with hidden variant. 19 + #[derive(Facet)] 20 + #[repr(C)] 21 + enum TestEnum { 22 + /// This variant should be visible. 23 + Visible, 24 + /// This variant should be hidden. 25 + #[facet(hierconf::hide)] 26 + Hidden, 27 + /// Another visible variant. 28 + AnotherVisible, 29 + } 30 + 31 + #[derive(Facet)] 32 + #[facet(hierconf::app_name("hidetest"))] 33 + #[facet(hierconf::date("2025-01-15"))] 34 + struct ConfigWithEnum { 35 + /// Enum field. 36 + test_enum: TestEnum, 37 + } 38 + 39 + #[test] 40 + fn hierconf_mangen_hide_fields() { 41 + let man_page = generate_man_page::<TestConfig>().unwrap(); 42 + let expected = include_str!("struct.roff"); 43 + assert_eq!(man_page, expected); 44 + } 45 + 46 + #[test] 47 + fn hierconf_mangen_hide_variants() { 48 + let man_page = generate_man_page::<ConfigWithEnum>().unwrap(); 49 + let expected = include_str!("enum.roff"); 50 + assert_eq!(man_page, expected); 51 + }
+37
crates/hierconf-mangen/tests/hide_attribute/struct.roff
··· 1 + .ie \n(.g .ds Aq \(aq 2 + .el .ds Aq ' 3 + .TH HIDETEST 5 2025-01-15 hierconf 4 + .SH NAME 5 + hidetest \- configuration file format 6 + .SH SYNOPSIS 7 + Configuration documentation. 8 + .PP 9 + See \fBDESCRIPTION\fR for configuration parameters and \fBFILES\fR for configuration file locations. 10 + .SH DESCRIPTION 11 + The \fIhidetest\fR configuration file uses the TOML format. 12 + 13 + Configuration files are checked in order of precedence, and the first file that exists is loaded. See the \fBFILES\fR section for details. 14 + 15 + .SS "Configuration structure" 16 + .TP 17 + \fBvisible_field\fR (\fIString\fR) 18 + This field should be visible. 19 + 20 + .TP 21 + \fBanother_visible\fR (\fIu16\fR) 22 + Another visible field. 23 + 24 + .SH FILES 25 + Configuration files are checked in the following order of precedence (highest to lowest). The first file that exists is loaded. 26 + 27 + .TP 28 + \fBtests/hidetest/config.toml\fR 29 + Test\-specific configuration file. 30 + 31 + .TP 32 + \fB/etc/hidetest/config.toml\fR 33 + System\-wide configuration file. 34 + 35 + .TP 36 + \fB/usr/share/etc/hidetest/config.toml\fR 37 + Distribution\-provided defaults.