Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to set incremental keys #329

Closed
1 task done
ghost opened this issue Oct 7, 2022 · 1 comment
Closed
1 task done

Able to set incremental keys #329

ghost opened this issue Oct 7, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Oct 7, 2022

Version

1.67.0

Describe the bug

If key name is - in data source, then it would be seen as special syntax for auto-increment key name start from 1, and every section is independent on counter.

I want to add a key value to the auto increment key name.

To reproduce

package main

import (
	"gopkg.in/ini.v1"
	"log"
)

func main() {
	cfgs, err := ini.Load([]byte(`[features]
	-: Support read/write comments of keys and sections
	-: Support auto-increment of key names
	-: Support load multiple files to overwrite key values`))
	if err != nil {
		log.Fatalf("Error: %s", err.Error())
	}
	newkey, _ := cfgs.Section("features").NewKey("-", "dasda")
	keys := cfgs.Section("features").KeyStrings()
	log.Println(newkey)
	log.Println(keys)
	// [#1 #2 #3 -]
}

But I print the added keys and get a key value other than #4, but -

Expected behavior

I want to get a key value like #4, but -

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ghost ghost added the bug Something isn't working label Oct 7, 2022
@unknwon
Copy link
Member

unknwon commented Oct 23, 2022

The transformation happens at parser stage, so for now I think you would have to save the file and reload back.

@unknwon unknwon changed the title How to set new key values How to set incremental keys Oct 23, 2022
@unknwon unknwon changed the title How to set incremental keys Able to set incremental keys Oct 23, 2022
@unknwon unknwon added enhancement New feature or request and removed bug Something isn't working labels Oct 23, 2022
@ghost ghost closed this as completed Nov 1, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant