import java.io.*;
import findinfiles.Finder;
public class Demo{
	public static void main(String[] args){
		if(args.length!=1){
			System.err.println("Please give me one and only one command line parameter. "+
			"Hint: Use quotation marks around your input (java Demo \"path to file/test.txt\").");
			return;
		}
		try{
			Finder.printFile(args[0]);
		}catch(IOException e){
			System.err.println("Error: Target file \""+args[0]+"\" cannot be read.");
		}

		System.out.print("Find a line: ");
		String input = System.console().readLine();
		try{
			if(Finder.findText(input, args[0])){
				System.out.println("Found");
			}else{
				System.out.println("Not found");
			}
			}catch(FileNotFoundException e){
				System.err.println("Error: Target file \""+args[0]+"\" cannot be found.");
			}catch(IOException e){
			System.err.println("Error: Target file \""+args[0]+"\" cannot be read.");
		}

		System.out.print("Find text in a line: ");
		input = System.console().readLine();
		try{
			if(Finder.findText2(input, args[0])){
				System.out.println("Found");
			}else{
				System.out.println("Not found");
			}
			}catch(FileNotFoundException e){
				System.err.println("Error: Target file \""+args[0]+"\" cannot be found.");
			}catch(IOException e){
			System.err.println("Error: Target file \""+args[0]+"\" cannot be read.");
		}

		System.out.print("Find case insensitive text in a line: ");
		input = System.console().readLine();
		try{
			if(Finder.findText3(input, args[0])){
				System.out.println("Found");
			}else{
				System.out.println("Not found");
			}
			}catch(FileNotFoundException e){
				System.err.println("Error: Target file \""+args[0]+"\" cannot be found.");
			}catch(IOException e){
			System.err.println("Error: Target file \""+args[0]+"\" cannot be read.");
		}

		System.out.print("Find whole word in a line: ");
		input = System.console().readLine();
		try{
			if(Finder.findText4(input, args[0])){
				System.out.println("Found");
			}else{
				System.out.println("Not found");
			}
			}catch(FileNotFoundException e){
				System.err.println("Error: Target file \""+args[0]+"\" cannot be found.");
			}catch(IOException e){
			System.err.println("Error: Target file \""+args[0]+"\" cannot be read.");
		}
	}
}