alecthomas / alecthomas/kong-toml

add an example of using nested structs in the README

オープン
#2 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Go
スター
5
フォーク
0
PR マージ指標
30日以内にマージされた PR はありません

説明

I want to use TOML and nested structs. Below is my code, which comes from an example at .

```go
package main

import (
"fmt"

"github.com/alecthomas/kong"
kongtoml "github.com/alecthomas/kong-toml"
)

func main() {
var cfg struct {
Logging struct {
Level string `enum:"debug,info,warn,error" default:"info"`
Type string `enum:"json,console" default:"console"`
} `embed:"" prefix:"logging."`
}
kong.Parse(&cfg, kong.Configuration(kongtoml.Loader, "./config.toml"))
fmt.Printf("%+v", cfg)
}
```

The content of `config.toml` is:

```toml
logging.level = "warn"
```

However, the configuration file is not read correctly, and the output remains `{Logging:{Level:info Type:console}}`.

After debugging, I found that `config.toml` needs to be modified as follows:

```toml
"logging.level" = "warn"
```

At this point, the output is `{Logging:{Level:warn Type:console}}`, which meets expectations.

I believe fundamentally, this is because `.` is a special character in TOML affecting the parsing, so quotes need to be added around the field names to wrap them up.

However, for users following README, they expect to be able to directly use `logging.level = "warn"`. The current behavior may confuse users. Could you please add examples with nested data structures to the README of this repo? Thank you!

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。