Browse Source

adapt yaml indent

Fabian Peter Hammerle 7 years ago
parent
commit
9d3c7a6018
7 changed files with 17 additions and 15 deletions
  1. 5 7
      README.md
  2. 1 1
      hardware_address.h
  3. 0 2
      link.cpp
  4. 1 1
      link.h
  5. 4 1
      list.h
  6. 4 1
      vector.h
  7. 2 2
      yaml.h

+ 5 - 7
README.md

@@ -14,28 +14,26 @@ apt install libmnl-dev linux-libc-dev g++
 $ ipyml
 links:
 - ifname: lo
-  address: 00:00:00:00:00:00
-  broadcast: 00:00:00:00:00:00
   mtu: 65536
   operstate: unknown
   addresses:
-    - 127.0.0.1
+  - 127.0.0.1
 - ifname: eth0
   address: 11:22:33:44:55:66
   broadcast: ff:ff:ff:ff:ff:ff
   mtu: 1500
   operstate: up
   addresses:
-    - 192.168.2.101
-    - fe80::1322:33ff:fe44:5566
+  - 192.168.2.101
+  - fe80::1322:33ff:fe44:5566
 - ifname: wlan0
   address: 77:88:99:00:aa:bb
   broadcast: ff:ff:ff:ff:ff:ff
   mtu: 1500
   operstate: up
   addresses:
-    - 192.168.20.11
-    - fe80::7588:99ff:fe00:aabb
+  - 192.168.20.11
+  - fe80::7588:99ff:fe00:aabb
 
 ```
 

+ 1 - 1
hardware_address.h

@@ -47,7 +47,7 @@ public:
 
   void write_yaml(std::ostream &stream,
                   const yaml_indent_level_t indent_level = 0) const {
-    stream << format();
+    stream << format() << '\n';
   }
 };
 

+ 0 - 2
link.cpp

@@ -51,12 +51,10 @@ void Link::write_yaml(std::ostream &stream,
   if (address.specified()) {
     stream << indent << "address: ";
     address.write_yaml(stream);
-    stream << "\n";
   }
   if (broadcast.specified()) {
     stream << indent << "broadcast: ";
     broadcast.write_yaml(stream);
-    stream << "\n";
   }
   stream << indent << "mtu: " << mtu << "\n";
   stream << indent << "operstate: ";

+ 1 - 1
link.h

@@ -3,8 +3,8 @@
 
 #include "address.h"
 #include "hardware_address.h"
-#include "operstate.h"
 #include "list.h"
+#include "operstate.h"
 #include "yaml.h"
 
 #include <linux/netlink.h>

+ 4 - 1
list.h

@@ -10,10 +10,13 @@
 template <class T> class list : public std::list<T>, YamlObject {
 public:
   void write_yaml(std::ostream &stream,
-                  const yaml_indent_level_t indent_level = 0) const {
+                  yaml_indent_level_t indent_level = 0) const {
     if (this->empty()) {
       stream << "[]";
     } else {
+      if (indent_level > 2) {
+        indent_level -= 2;
+      }
       const std::string indent(indent_level, ' ');
       stream << "\n";
       for (auto it = this->begin(); it != this->end(); it++) {

+ 4 - 1
vector.h

@@ -10,10 +10,13 @@
 template <class T> class vector : public std::vector<T>, YamlObject {
 public:
   void write_yaml(std::ostream &stream,
-                  const yaml_indent_level_t indent_level = 0) const {
+                  yaml_indent_level_t indent_level = 0) const {
     if (this->empty()) {
       stream << "[]";
     } else {
+      if (indent_level > 2) {
+        indent_level -= 2;
+      }
       const std::string indent(indent_level, ' ');
       stream << "\n";
       for (auto it = this->begin(); it != this->end(); it++) {

+ 2 - 2
yaml.h

@@ -1,13 +1,13 @@
 #ifndef _IPYML_YAML_H
 #define _IPYML_YAML_H
 
-#include <ostream>
+#include <ostream> // std::ostream
 
 typedef unsigned char yaml_indent_level_t;
 
 class YamlObject {
   virtual void write_yaml(std::ostream &stream,
-                          const yaml_indent_level_t indent_level = 0) const = 0;
+                          yaml_indent_level_t indent_level = 0) const = 0;
 };
 
 #endif