You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let me preface this by apologizing in advance if this is more of a problem with my lack of experience with Go/this library than an actual bug, still pretty new to using both.
I'm attempting to make a program that adds one line to an INI-formatted file under a specific section and then saves it without touching the rest of the file. Yet whenever I do this, go-ini seems to erroneously add extra quotation marks around certain values despite me never telling the library to touch those lines.
funcpatch_def(defstring) {
fmt.Println("Patching DEF file...")
file_data, err:=os.ReadFile(def)
check_error(err)
parsed_ini, err:=ini.LoadSources(ini.LoadOptions{AllowNonUniqueSections: true, IgnoreInlineComment: true, SkipUnrecognizableLines: true}, file_data)
check_error(err)
fors:=rangeparsed_ini.Sections() {
varsect_name=parsed_ini.Sections()[s].Name()
// find the Files sectionifstrings.EqualFold(sect_name, "Files") {
fork:=rangeparsed_ini.Sections()[s].Keys() {
varkey_name=parsed_ini.Sections()[s].KeyStrings()[k]
ifstrings.EqualFold(key_name, "cmd") {
// get the value of cmdcmd_value:=parsed_ini.Sections()[s].Key(key_name).String()
// strip the cmd value to just the path, and then add the output filename to itdat_value:=filepath.Join(filepath.Dir(cmd_value), output_file)
// add our new path to the INI and save itparsed_ini.Sections()[s].NewKey("movelist", dat_value)
parsed_ini.SaveTo(def)
return
}
}
}
}
fmt.Println("Iguana wasn't able to find a command file from this DEF. No changes have been made.")
return
}
Setting IgnoreInlineComment: true to false does not create these extra quotation marks, but it also forces every single inline comment to be on a new line, which I don't want.
Expected behavior
The INI file I'm testing that's giving these problems (if you're testing/attempting to reproduce this issue with the full program source linked above, you must give this file a .def extension): skapon_def.txt
What I want to do is simply add a line under the [Files] section, without touching anything else in the file (comments, other key-value pairs, etc.):
The resulting program will, depending on the setting of IgnoreInlineComment, either add extra quotation marks to fields I'm not editing and thus corrupting the values, or force every single inline comment to be on a separate line when saving, neither of which is ideal.
The program this function comes from, Iguana, is intended to generate and patch characters for Ikemen GO, a free and open source fighting game engine. I mostly bring this up to clarify that the file format Iguana interfaces with, .def, uses INI syntax and should behave the same as any other INI file as far as this library is concerned.
I'm sure there's some easier way to do what I'm wanting to do here (adding a single line to a text file in a specific place), but it'd be nice to at least know if this is some weird edge case with this library or if I'm doing something wrong here.
I have an issue over on my project repo that documents this issue as well, if more context is necessary: SuperFromND/iguana#10
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
Version
v1.67.0
Describe the bug
Let me preface this by apologizing in advance if this is more of a problem with my lack of experience with Go/this library than an actual bug, still pretty new to using both.
I'm attempting to make a program that adds one line to an INI-formatted file under a specific section and then saves it without touching the rest of the file. Yet whenever I do this, go-ini seems to erroneously add extra quotation marks around certain values despite me never telling the library to touch those lines.
To reproduce
The function in question causing the problem, as lifted from my Iguana project (linked in case you need full source code instead of just a snippet):
Setting
IgnoreInlineComment: true
tofalse
does not create these extra quotation marks, but it also forces every single inline comment to be on a new line, which I don't want.Expected behavior
The INI file I'm testing that's giving these problems (if you're testing/attempting to reproduce this issue with the full program source linked above, you must give this file a
.def
extension):skapon_def.txt
What I want to do is simply add a line under the
[Files]
section, without touching anything else in the file (comments, other key-value pairs, etc.):Turning it into this:
The resulting program will, depending on the setting of
IgnoreInlineComment
, either add extra quotation marks to fields I'm not editing and thus corrupting the values, or force every single inline comment to be on a separate line when saving, neither of which is ideal.Additional context
The program this function comes from, Iguana, is intended to generate and patch characters for Ikemen GO, a free and open source fighting game engine. I mostly bring this up to clarify that the file format Iguana interfaces with,
.def
, uses INI syntax and should behave the same as any other INI file as far as this library is concerned.I'm sure there's some easier way to do what I'm wanting to do here (adding a single line to a text file in a specific place), but it'd be nice to at least know if this is some weird edge case with this library or if I'm doing something wrong here.
I have an issue over on my project repo that documents this issue as well, if more context is necessary: SuperFromND/iguana#10
Code of Conduct
The text was updated successfully, but these errors were encountered: