package se.blea.flexiconf.cli;

import se.blea.flexiconf.ConfigOptions;
import se.blea.flexiconf.Schema;
import se.blea.flexiconf.SchemaOptions;
import se.blea.flexiconf.javaapi.*;

import java.util.List;

/**
 * @author Tristan Blease (tblease@groupon.com)
 */
public class JavaCLI {
    public static void main(String[] args) {
        SchemaOptions schemaOpts = SchemaOptions.withSourceFile("src/main/resources/sample_schema.conf");
        Schema schema = Parser.parseSchema(schemaOpts);

        ConfigOptions configOpts = ConfigOptions.withSourceFile("src/main/resources/sample_config.conf")
            .ignoreUnknownDirectives()
            .ignoreMissingGroups()
            .withSchema(schema);

        Config config = Parser.parseConfig(configOpts);

        printArgs(config.getDirectives());

        System.out.println("default > connectTimeout > " + config.getDirective("defaults")
                .getDirective("connectTimeout")
                .getIntArg("ms"));

        System.out.println("Filtered args");

        printArgs(config.getDirectives("defaults", "destination"));

        System.out.println(config.renderTree());
        System.out.println(config.getWarnings().size());
        config.getWarnings().forEach(System.out::println);
    }

    private static void printArgs(List<Directive> nodes) {
        nodes.forEach((node) -> {
            System.out.println(node.getName());
            node.getArgs().forEach((arg) -> {
                System.out.println(String.format(">> %s: %s", arg.getName(), arg.getKind()));
            });

            printArgs(node.getDirectives());
        });
    }
}

@@ -1196,23 +1196,46 @@
 ize());%0A
+%0A
        
+ for (String warning :
  config.
@@ -1247,25 +1247,32 @@
 rnings()
-.forEach(
+) %7B%0A            
 System.o
@@ -1277,19 +1277,36 @@
 .out
-::
+.
 println
-);
+(warning);%0A        %7D
 %0A   
@@ -1380,31 +1380,36 @@
     
-nodes.forEach((node) -%3E
+for (Directive node : nodes)
  %7B%0A 
@@ -1471,39 +1471,43 @@
     
-node.getArgs().forEach((arg) -%3E
+for (Argument arg : node.getArgs())
  %7B%0A 
@@ -1612,18 +1612,16 @@
        %7D
-);
 %0A%0A      
@@ -1655,24 +1655,24 @@
 ectives());%0A
+
         %7D);%0A
@@ -1668,18 +1668,16 @@
        %7D
-);
 %0A    %7D%0A%7D

Remove forEach calls for Java 7 support