Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added arguments parser #16

Merged
merged 3 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#add any supporting commands to create avglength.jar, the name of the java JAR file.
ant make-jar

#add any supporting commands to print team info when passed the --team command-line argument
java -jar avglength.jar --team

#java -jar avglength.jar --team
java -jar jars/avglength.jar --team
#add any supporting commands to print the documentation on console when --help is passed as a command-line argument
java -jar avglength.jar --help
#java -jar avglength.jar --help
java -jar jars/avglength.jar --help
40 changes: 40 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="PA1">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.8"/>
<property name="source" value="1.8"/>
<path id="PA1.classpath">
<pathelement location="bin"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="PA1.classpath"/>
</javac>
</target>
<target name="make-jar" depends="build">
<mkdir dir="jars"/>
<jar destfile="jars/avglength.jar" basedir="bin">
<manifest>
<attribute name="Main-Class" value="Main"/>
</manifest>
</jar>
</target>
</project>
96 changes: 96 additions & 0 deletions src/ParseArguments.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// import java.io.File;

public class ParseArguments {
// private String filename;
// private String delimiter;

public ParseArguments(String[] args) {
try {
String arg = args[0]; // ArrayIndexOutOfBoundsException
if (arg.equals("--team")) {
System.out.println();
teamInfo();
System.out.println();
System.exit(0);
} else if (arg.equals("--help")) {
System.out.println();
manual();
System.out.println();
System.exit(0);
}
// else {

// Checker check = new Checker(args);
// check.isChecked();

// String filePath = args[0];
// File file = new File(filePath);

// // check if file exists
// if(!file.exists()) {
// System.out.println("file doesn't exists at file path : " + filePath);
// System.exit(0);
// }

// //default delimiter is '.'
// String Delimiter = ".";
// if(args.length > 1) {
// Delimiter = args[1];
// }

// //set the filename and Delimiter
// setFilename(filePath);
// setDelimiter(Delimiter);
// }
} catch (ArrayIndexOutOfBoundsException e) {
//In case user doesn't provide any arguments to jar file
System.out.println("\nPlease Enter arguments !\t(For more help, use '--help' tag)\n");
System.exit(-1);
}
}

// public void setFilename(String fileName) {
// this.filename = fileName;
// }

// public void setDelimiter(String delimiter) {
// this.delimiter = delimiter;
// }

// public String getFilename() {
// return this.filename;
// }

// public String getDelimiter() {
// return this.delimiter;
// }

private void teamInfo() {
System.out.println("<< Team Info >>\n");
System.out.println("Team Name : Software Fighters");
System.out.println("\nMembers : ");
System.out.println("\tManjeet Kapil (180010021) ");
System.out.println("\tHarsh Raj (180010017) ");
System.out.println("\tShriram Ghadge (180010015) ");
System.out.println("\tRupesh Kalantre (180010029) ");
}

private void manual() {
System.out.println("--------- MANUAL ----------\n");
String manual = "(This is a command-line program written in java to find no. of " +
"lines, words, average length in your Essay/writting.)\n" +
"\n\nHow-To guide : \n" +
"\n\tTo get the team Information : use '--team' flag with the jar file." +
"\n\t> $ java -jar <PATH TO JAR FILE> --team\n" +
"\n\tTo get the manual : use '--help' flag with the jar file" +
"\n\t> $ java -jar <PATH TO JAR FILE> --help\n" +
"\n\tTo use the jar file to find no. of average lines, words, total lines, execute following command:" +
"\n\t> $ java -jar <PATH TO JAR FILE> <PATH TO YOUR ESSAY FILE> <DELIMITER IF ANY> <Minimum Word Length>\n" +
"\n\t**Note : here delimiter means the character with which your sentence ends. " +
"By default sentence ends with '.' character" +
"\n\tDefault value of minimum word length is 4, this is optional argument";

System.out.println(manual);
System.out.println("\n--------- END OF MANUAL ----------");
}
}