zwq00000 / gcfg

Automatically exported from code.google.com/p/gcfg
Other
0 stars 0 forks source link

Support for `-` in variable/section names #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The `gitconfig` format supports multi-word variables and sections where each 
word is seperated with `-`.

Do you plan such feature in gcfg? Here is how I imagine it:

    [section-name]
        variable-name = true

To be mapped to:

    type Config struct {
        SectionName struct {
            VariableName bool
        }
    }

Original issue reported on code.google.com by v.ki...@gmail.com on 22 Nov 2013 at 3:42

GoogleCodeExporter commented 8 years ago
This issue was closed by revision cf5bf950858d.

Original comment by speter....@gmail.com on 23 Nov 2013 at 12:21

GoogleCodeExporter commented 8 years ago
Thank you for the feedback. It has been supported already, but perhaps poorly 
documented. I added an example with hyphens:

http://godoc.org/code.google.com/p/gcfg#example-ReadStringInto--Hyphens

Original comment by speter....@gmail.com on 23 Nov 2013 at 12:28

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
That Camel_Case_But_With_Snakes_In_It naming as awful! Would you approve a 
patch from me, where multiple words make a real CamelCase names?

Original comment by v.ki...@gmail.com on 24 Nov 2013 at 12:20

GoogleCodeExporter commented 8 years ago
Actually it doesn't have to be camel-case, case-insensitive matching is used. 
(Only the first letter must be capital to make it accessible through "reflect".)

Gcfg currently maps one character in config variable name to one character in 
Go field name. It may not be the most visually appealing representation, but 
having a straightforward rule has the advantage of simplicity.

Even if we change something, it must keep working for the existing users 
(including underscores and case-insensitivity). I don't quite understand what 
your proposed change would mean specifically. Would "variablename" 
"variable-name" and "var-iablen-ame" all set VariableName? I think that would 
just add confusion.

Original comment by speter....@gmail.com on 24 Nov 2013 at 11:46

GoogleCodeExporter commented 8 years ago
> having a straightforward rule has the advantage of simplicity.

I think the rule I'm proposing is quite simple, too. Only the first letter and 
these with `-` before them should be upper case. Every other letter has to be 
lower case.

> I don't quite understand what your proposed change would mean specifically. 
Would "variablename" "variable-name" and "var-iablen-ame" all set VariableName? 
I think that would just add confusion.

variablename -> Variablename
variable-name -> VariableName
var-iablen-ame -> VarIablenAme

> Even if we change something, it must keep working for the existing users 
(including underscores and case-insensitivity).

Now, that's the real issue here :)

Original comment by v.ki...@gmail.com on 25 Nov 2013 at 11:40

GoogleCodeExporter commented 8 years ago
Sorry for not following up. I have added support for specifying mapping via 
struct tag, similarly to the encoding/* packages. See 
http://godoc.org/code.google.com/p/gcfg#example-ReadStringInto--Tags .

Note that in addition to the compatibility issue, your rule doesn't consider 
acronyms etc that are idiomatically written in all caps in field names (e.g. 
HTTPPort, UserID). Moreover, it also doesn't consider consecutive hyphens, and 
scripts that don't have upper-lower case, although those are less common. 
Extending it to support these is not straightforward and would make the rule 
much less simple.

Original comment by speter....@gmail.com on 24 Feb 2014 at 10:03