package com.jobst_software.markdown2any;


import com.jobst_software.gjc2sx.PrintableGj;
import com.jobst_software.gjc2sx.helpers.Ut;
import com.jobst_software.gjc2sx.helpersx.Utx;





public class  MarkdownReader   extends AbstractMarkdownReader {


public static void  main( String[] args)
{
  boolean  showUsage 			 = false;
  boolean  sc        			 = false;


  try
  {
	  if(  		  args.length == 10
			  &&  "--manual".equals(args[0]) 
		  	  &&  PROJECTS_TRACKERS_ISSUES_ARG.equals(args[PROJECTS_TRACKERS_ISSUES_ARG_NO]) 
		  	  &&  ISSUES_WHERE_ARG.equals(args[ISSUES_WHERE_ARG_NO])
		  	  &&  RESOURCE_URL_ARG.equals(args[RESOURCE_URL_ARG_NO]) 
		  	  &&  RESOURCE_PATH_ARG.equals(args[RESOURCE_PATH_ARG_NO]) ) {
		  
		  log( "gestartet " + Ut.formatArray( args, " "));
		  
		  MarkdownDocument 	doc = new  MarkdownDocument( args);   
		  doc.init();
		  
		  MarkdownSqlSource  sqlSource = new  MarkdownSqlSource( doc, args);                      
		  sqlSource.init();
		  
		  String  									  markdown_out_filename = args[1] + ".md";
		  PrintableGj  	   out = new  MarkdownWriter( markdown_out_filename);   out.init();
		  doc.writeTo( 	   out, sqlSource);
		  out.dispose();   out = null;

		  sqlSource.dispose();     
		  sqlSource = null;		  
		  
		  doc.dispose();
		  doc = null;
		  
		  log( "beendet " + Ut.formatArray( args, " "));
		  
	  	  sc = true;
	  
	  }
	  else {
		  showUsage = true;
	  }

  }
  catch( Exception exc) {
	  log( "failed (" + Utx.excMsgWithStack(exc) + ")");
  }
  
  
  if( showUsage == true ) {
	System.err.println("usage:  java  " + MarkdownReader.class.getName()
							+ "  --manual Handbuch  " 
							+ "  " + PROJECTS_TRACKERS_ISSUES_ARG 	+ " public.projects,public.trackers,public.issues,public.attachments" 
							+ "  " + ISSUES_WHERE_ARG 		    	+ " \"tracker_id in (38,39,40,41,43) and status_id = 51  and  project_id <> 12\" "
							+ "  " + RESOURCE_URL_ARG				+ " http://www.jobst-software.com"
							+ "  " + RESOURCE_PATH_ARG				+ " ./files"
							);
  }


  System.exit( sc == true  &&  showUsage == false ? 0 : 1);
}


public static void  log( 						           String t) {
  System.out.println( MarkdownReader.class.getSimpleName() + ": " + t);
}


}
