Skip to content

Commit

Permalink
[knf] Add 'Alias' method + Add property name validation + Code refact…
Browse files Browse the repository at this point in the history
…oring
  • Loading branch information
andyone committed Apr 29, 2024
1 parent 9d6194a commit ee80744
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 116 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Changelog

### 12.120.0

- `[knf]` Added `Alias` method
- `[knf]` Added property name validation for all getters
- `[knf]` Code refactoring

### 12.119.0

- `[initsystem]` Added [launchd](https://www.launchd.info) support
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.119.0"
const VERSION = "12.120.0"

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

Expand Down
42 changes: 42 additions & 0 deletions knf/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ func ExampleReload() {
}
}

func ExampleAlias() {
err := Global("/path/to/your/config.knf")

if err != nil {
fmt.Printf("Error: %v\n", err)
return
}

// Add alias for renamed property "user:username"
Alias("user:username", "user:name")

fmt.Printf("Value from config: %s\n", GetS("user:name"))
}

func ExampleGetS() {
err := Global("/path/to/your/config.knf")

Expand Down Expand Up @@ -373,6 +387,34 @@ func ExampleConfig_Reload() {
}
}

func ExampleConfig_Alias() {
cfg, err := Parse([]byte(`
[user]
username: john
uid: 512
is-admin: true
priority: 3.7
default-mode: 0644
timeout: 3m
created: 1654424130
timezone: Europe/Madrid
labels: system admin
`))

if err != nil {
fmt.Printf("Error: %v\n", err)
return
}

// Add alias for renamed property "user:username"
cfg.Alias("user:username", "user:name")

fmt.Printf("Value from config: %s\n", cfg.GetS("user:name"))

// Output:
// Value from config: john
}

func ExampleConfig_GetS() {
cfg, err := Parse([]byte(`
[user]
Expand Down
Loading

0 comments on commit ee80744

Please sign in to comment.