From 486707d05f4d535d854243ab6bb07482caadbfa0 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 28 Oct 2024 13:25:59 +0300 Subject: [PATCH] [knf] Added helper 'Q' --- CHANGELOG.md | 4 ++++ knf/example_test.go | 3 +++ knf/knf.go | 6 ++++++ knf/knf_test.go | 4 ++++ version.go | 2 +- 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90d0e5c7..a03d29aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### [13.9.2](https://kaos.sh/ek/13.9.2) + +- `[knf]` Added helper `Q` + ### [13.9.1](https://kaos.sh/ek/13.9.1) - `[errors]` Fixed bug with extra newline character at the end of `Error` output diff --git a/knf/example_test.go b/knf/example_test.go index a43fb8cd..c848ae75 100644 --- a/knf/example_test.go +++ b/knf/example_test.go @@ -25,6 +25,9 @@ func ExampleGlobal() { // Read string value GetS("main:string") + // Use helper Q to create full property name + GetS(Q("main", "string")) + // Read integer value GetI("main:int") diff --git a/knf/knf.go b/knf/knf.go index 919053e5..84d89365 100644 --- a/knf/knf.go +++ b/knf/knf.go @@ -423,6 +423,12 @@ func Validate(validators Validators) errors.Errors { return global.Validate(validators) } +// Q is a helper to create a valid full property name (section + delimiter +// + property name) +func Q(section, prop string) string { + return section + _SYMBOL_DELIMITER + prop +} + // ////////////////////////////////////////////////////////////////////////////////// // // Add adds given validators and returns new slice diff --git a/knf/knf_test.go b/knf/knf_test.go index 08a33f97..0f591e3c 100644 --- a/knf/knf_test.go +++ b/knf/knf_test.go @@ -747,6 +747,10 @@ func (s *KNFSuite) TestKNFParserExceptions(c *check.C) { c.Assert(err.Error(), check.Equals, "Error at line 3: Unknown property {abcd:test}") } +func (s *KNFSuite) TestHelpers(c *check.C) { + c.Assert(Q("section", "prop"), check.Equals, "section:prop") +} + // ////////////////////////////////////////////////////////////////////////////////// // func (s *KNFSuite) BenchmarkBasic(c *check.C) { diff --git a/version.go b/version.go index fbca6c6a..cc2b131f 100644 --- a/version.go +++ b/version.go @@ -8,4 +8,4 @@ package ek // ////////////////////////////////////////////////////////////////////////////////// // // VERSION is current ek package version -const VERSION = "13.9.1" +const VERSION = "13.9.2"