package com.dw.lib.cli;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map.Entry;
import java.util.Set;

import com.dw.lib.FileUtils;
import com.dw.lib.HttpPostHelper;
import com.dw.lib.JsonOp;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class PostCLI {

	public static void main(String[] args) {
		if(args.length == 0) {
			System.out.println("post <config file> <body file> <output file>");
			System.out.println("post <config file> <body file> #output default to output.txt ");
			System.out.println("example config:");
			System.out.println("{");
			System.out.println("    \"url\":\"https://jsonplaceholder.typicode.com/posts\",");
			System.out.println("    \"method\": \"post\",");
			System.out.println("    \"bodyType\": \"json\",");
			System.out.println("    \"headers\": {");
			System.out.println("        \"Content-type\": \"application/json; charset=UTF-8\",");
			System.out.println("        \"Authorization\": \"Basic xxxxxxxxx\"");
			System.out.println("    }");
			System.out.println("}");
			System.out.println("<body file> is json file or xml file");

			return;
		}
		
		String outputFilePath = "output.txt";
		if(args.length >= 3) {
			outputFilePath = args[2]; 
		}
		
		try {
			HttpPostHelper helper = new HttpPostHelper();
			if (args.length == 1) {
				helper.Post(args[0], null, outputFilePath);
			}
			else if(args.length == 2) {
				helper.Post(args[0], args[1], outputFilePath);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

}

@@ -622,34 +622,36 @@
 ) %7B%0A%09%09%09S
-ystem.out.println(
+tring%5B%5D helpInfo = %7B
 %22post %3Cc
@@ -692,33 +692,15 @@
 le%3E%22
-);
+,
 %0A%09%09%09
-System.out.println(
+%09%09
 %22pos
@@ -762,33 +762,15 @@
 xt %22
-);
+,
 %0A%09%09%09
-System.out.println(
+%09%09
 %22exa
@@ -786,61 +786,25 @@
 ig:%22
-);
+,
 %0A%09%09%09
-System.out.println(%22%7B%22);
+%09%09%22%7B%22,
 %0A%09%09%09
-System.out.println(
+%09%09
 %22   
@@ -864,33 +864,15 @@
 %5C%22,%22
-);
+,
 %0A%09%09%09
-System.out.println(
+%09%09
 %22   
@@ -898,33 +898,15 @@
 %5C%22,%22
-);
+,
 %0A%09%09%09
-System.out.println(
+%09%09
 %22   
@@ -934,33 +934,15 @@
 %5C%22,%22
-);
+,
 %0A%09%09%09
-System.out.println(
+%09%09
 %22   
@@ -961,33 +961,15 @@
 : %7B%22
-);
+,
 %0A%09%09%09
-System.out.println(
+%09%09
 %22   
@@ -1032,33 +1032,15 @@
 %5C%22,%22
-);
+,
 %0A%09%09%09
-System.out.println(
+%09%09
 %22   
@@ -1087,93 +1087,39 @@
 x%5C%22%22
-);
+,
 %0A%09%09%09
-System.out.println(
+%09%09
 %22    %7D%22
-);
+,
 %0A%09%09%09
-System.out.println(%22%7D%22);
+%09%09%22%7D%22,
 %0A%09%09%09
-System.out.println(
+%09%09
 %22%3Cbo
@@ -1152,18 +1152,84 @@
 ml file%22
-);
+%7D;%0A%09%09%09%0A%09%09%09for(String s : helpInfo) %7B%0A%09%09%09%09System.out.println(s);%0A%09%09%09%7D
 %0A%0A%09%09%09ret

update help info for post command