jxnkwlp / NginxConfigParser

A .net standard library for reading and writing nginx configuration files.
21 stars 6 forks source link

How to set/change comment for existing group? #13

Open DrTiBiBo opened 2 months ago

DrTiBiBo commented 2 months ago

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

jxnkwlp commented 2 months ago

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();