package com.dw.lib.cli;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.dw.lib.FileUtils;

public class CppCpCLI {

	public static void help() {
		System.out.println("cppcp  <input file> <output folder> <final-file>");
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		if(args.length != 3) {
			help();
			return;
		}
		
		FileUtils fileUtils = new FileUtils();
		String mainPath = args[1];
		StringBuilder sb = new StringBuilder();
		List<String> output = new ArrayList<String>();
		try {
			List<String> lines = fileUtils.fileToList(args[0]);
			
			for(String line : lines) {
				String[] paths = line.split("/");
				sb.append(mainPath);
				for(int i=0;i<paths.length-1;i++) {
					if(!paths[i].equals("."))
						sb.append(paths[i] + "/");
				}
				output.add("mkdir -p " + sb.toString());
				output.add("cp " + line + " " + sb.append(paths[paths.length-1]));
				sb.setLength(0);
			}
			
			fileUtils.listToFile(output, args[2]);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

@@ -245,19 +245,65 @@
 r%3E %3C
-final-file%3E
+sh-output%3E%22);%0A%09%09System.out.println(%22output folder: ./cpp/
 %22);%0A

update cppcp command line