Skip to content

Commit

Permalink
Merge pull request #443 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.107.0
  • Loading branch information
andyone authored Mar 17, 2024
2 parents 3f409e3 + 3fd3ec4 commit 808191d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### 12.107.0

* `[knf/united]` Added method `Simple`

### 12.106.0

* `[knf/united]` Added method `ToOption` with shortcut `O`
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.106.0"
const VERSION = "12.107.0"

// ////////////////////////////////////////////////////////////////////////////////// //

Expand Down
13 changes: 12 additions & 1 deletion knf/united/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ func ExampleCombine() {
)

Combine(
// Create mapping manually
Mapping{optOne, ToOption(optOne), ToEnvVar(optOne)},
Mapping{optTwo, ToOption(optTwo), ToEnvVar(optTwo)},
// Create simple mapping
Simple(optTwo),
)

// Read string value
Expand Down Expand Up @@ -92,6 +94,15 @@ func ExampleCombine() {
GetL("section:list")
}

func ExampleSimple() {
m := Simple("test:option-one")

fmt.Printf("%s → --%s + %s\n", m.Property, m.Option, m.Variable)

// Output:
// test:option-one → --test-option-one + TEST_OPTION_ONE
}

func ExampleToOption() {
fmt.Println(ToOption("section:time-duration"))

Expand Down
6 changes: 6 additions & 0 deletions knf/united/united.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func Combine(mappings ...Mapping) {
global = config
}

// Simple creates simple mapping for knf property
// section:property → --section-property + SECTION_PROPERTY
func Simple(name string) Mapping {
return Mapping{name, O(name), E(name)}
}

// ToOption converts knf property name to option name
func ToOption(name string) string {
return strutil.ReplaceAll(strings.ToLower(name), "_:", "-")
Expand Down
6 changes: 6 additions & 0 deletions knf/united/united_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,10 @@ func (s *UnitedSuite) TestHelpers(c *C) {
c.Assert(E(""), Equals, "")
c.Assert(E("section:prop-one"), Equals, "SECTION_PROP_ONE")
c.Assert(E("Section:Prop-Two"), Equals, "SECTION_PROP_TWO")

m := Simple("test:option-one")

c.Assert(m.Property, Equals, "test:option-one")
c.Assert(m.Option, Equals, "test-option-one")
c.Assert(m.Variable, Equals, "TEST_OPTION_ONE")
}

0 comments on commit 808191d

Please sign in to comment.