package eu.netide.core.management.cli;

import eu.netide.core.api.IBackendManager;
import eu.netide.core.management.ManagementHandler;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * Created by arne on 04.02.16.
 */

@Command(scope = "netide", name = "loadComposition", description = "Load a composition XML file")
public class LoadComposition extends OsgiCommandSupport {

    @Argument(index = 0, name = "compositionFile", description = "The composition xml file to load", required = true, multiValued = false)
    String compositionFile;

    @Override
    protected Object doExecute() throws Exception {
        Path path = Paths.get(compositionFile).toAbsolutePath();
        String spec = new String(Files.readAllBytes(path));

        ManagementHandler.setConfigurationValue("eu.netide.core.caos", "compositionSpecification", spec);
        return null;
    }

}

@@ -800,16 +800,35 @@
 ption %7B%0A
+%0A        try %7B%0A    
         
@@ -884,16 +884,20 @@
 Path();%0A
+    
         
@@ -957,16 +957,20 @@
         
+    
 Manageme
@@ -1059,16 +1059,169 @@
  spec);%0A
+        %7D catch (java.nio.file.NoSuchFileException nsf) %7B%0A            System.out.printf(%22Composititon file %25s not found.%5Cn%22, compositionFile);%0A        %7D%0A
         

Print error if the composition file cannot be found