From 258d149af5674955d3083ff1d6017bea0cf6219d Mon Sep 17 00:00:00 2001 From: SteamedFish <69167+SteamedFish@users.noreply.github.com> Date: Mon, 25 Jul 2022 18:50:06 +0800 Subject: [PATCH] Print children in json, even if output:list is enabled Children structure is pretty useful, especially for NVMe disks. It is pretty hard to track which namespace belongs to which disk without it. --- src/core/hw.cc | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/core/hw.cc b/src/core/hw.cc index 1c1dad46..b52f2a07 100644 --- a/src/core/hw.cc +++ b/src/core/hw.cc @@ -1650,20 +1650,28 @@ string hwNode::asJSON(unsigned level) resources.clear(); } - if(!::enabled("output:list") && countChildren()>0) + if(countChildren()>0) { - out << "," << endl; - out << spaces(2*level+2); - out << "\"children\" : ["; + bool needcomma = false; + if(visible(getClassName())){ + out << "," << endl; + out << spaces(2*level+2); + out << "\"children\" : ["; + } for (unsigned int i = 0; i < countChildren(); i++) { - out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1); - if (visible(getChild(i)->getClassName()) && iasJSON(visible(getClassName()) ? level + 2 : 1); + + if(needcomma && strip(json)!="") { out << "," << endl; } + out << json; + needcomma |= strip(json)!=""; + } + if(visible(getClassName())){ + out << "]"; } - out << "]"; } if(visible(getClassName())) @@ -1672,20 +1680,6 @@ string hwNode::asJSON(unsigned level) out << "}"; } - if(::enabled("output:list") && countChildren()>0) - { - bool needcomma = visible(getClassName()); - for (unsigned int i = 0; i < countChildren(); i++) - { - string json = getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1); - - if(needcomma && strip(json)!="") - out << "," << endl; - out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1); - needcomma |= strip(json)!=""; - } - } - if (::enabled("output:list") && level == 0) { out << endl << "]" << endl;