package cloudcmd.cld;

import cloudcmd.cld.commands.Index;
import cloudcmd.common.FileUtil;
import cloudcmd.common.config.ConfigStorageService;
import cloudcmd.common.index.IndexStorageService;
import jpbetz.cli.CommandSet;

import java.io.File;

public class Main {

  @SuppressWarnings("unchecked")
  public static void main(String[] args) throws Exception
  {
    String configRoot = FileUtil.findConfigDir(FileUtil.getCurrentWorkingDirectory(), ".cld");

    if (configRoot == null)
    {
      System.err.println("Not in a cloudcmd project.  Please use cld init to create a project.");
      return;
    }

    ConfigStorageService.instance().init();

    try
    {
      IndexStorageService.instance().init();

      CommandSet app = new CommandSet("cld");
      app.addSubCommands(Index.class);
      app.invoke(args);
    }
    finally
    {
      IndexStorageService.instance().shutdown();
      ConfigStorageService.instance().shutdown();
    }
	}
}

@@ -451,17 +451,16 @@
 .cld%22);%0A
-%0A
     if (
@@ -495,112 +495,104 @@
     
-System.err.println(%22Not in a cloudcmd project.  Please use cld init to create a project.%22);%0A      return
+configRoot = System.getenv(%22HOME%22) + File.separator + %22.cld%22;%0A      new File(configRoot).mkdir()
 ;%0A  
@@ -629,32 +629,42 @@
 instance().init(
+configRoot
 );%0A%0A    try%0A    

add project root