NginxConfigParser icon indicating copy to clipboard operation
NginxConfigParser copied to clipboard

How to set/change comment for existing group?

Open DrTiBiBo opened this issue 1 year ago • 1 comments

Hello,

I'm trying to set/change comment for existing group, but no success.

Existing nginx config has 4 server blocks and I need to change some content inside and I would like to add comments for each server block. After this code the filed comment is empty for the first block:

var nginx = NginxConfig.LoadFrom(nginxConfigPath);
    nginx.AddOrUpdate("server[0]", "", true, "Some comment for the first server block");

Could you please tell me if it possible and how it is possible?

Thanks in advance

DrTiBiBo avatar Sep 03 '24 08:09 DrTiBiBo

It looks like a bug when change exist group block comment.

But, if remove and then add it again, can temporary fix this issues.

I will fix it as soon as possible.
Thanks.

string source = NginxConfig.Create()
	.AddOrUpdate("server[0]", "", true, "Comment1")
	.AddOrUpdate("server[1]", "", true, "Comment2") 
	// save file
	.ToString();

source.Dump();

NginxConfig.Load(source)
    // .Remove("server[0]")
	.AddOrUpdate("server[0]", "", true, "Comment1 changed")
	.AddOrUpdate("server[1]", "", true, "Comment2 changed")
	.ToString()
	.Dump();

jxnkwlp avatar Sep 04 '24 06:09 jxnkwlp