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

Improve the JMatrix Main class #49

Merged
merged 1 commit into from
Jun 20, 2023
Merged
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
70 changes: 46 additions & 24 deletions src/main/java/com/mitsuki/jmatrix/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,39 @@
import com.mitsuki.jmatrix.util.Options;
import com.mitsuki.jmatrix.util.XMLParser;

/**
* Main class for <b>JMatrix</b> library that provides some information such as <b>JMatrix</b> version.
*
* <p>This class does not provides API for build the matrix,
* it's just <i>useless<i> class if get imported.
*
* <p><b>Usage:</b></p>
*
* <pre>&nbsp;
* java -jar path/to/jmatrix.jar [-h|-V|-cr]
* </pre>
*
* @author <a href="https://github.com/mitsuki31" target="_blank">
* Ryuu Mitsuki</a>
* @version 1.2, 20 June 2023
* @since 1.0.0
* @see com.mitsuki.jmatrix.Matrix
*/
public class Main
{
private static XMLParser XML = new XMLParser(XMLParser.XMLType.CONFIG);
private static String programVersion = XML.getProperty("programName") + " " + getVersion();

public static void main(String[ ] args) {
String arg1 = null;
String arg2 = null;

XMLParser XML = new XMLParser(XMLParser.XMLType.CONFIG);

if (args.length >= 1 && args.length < 2) {
arg1 = args[0];
if (args.length == 2) {
arg2 = args[1];
}
}
else if (args.length > 1) {
} else if (args.length > 1) {
try {
throw new IllegalArgumentException("Too much arguments");
} catch (final Exception e) {
Options.raiseErrorMsg(e, 0);
} catch (final IllegalArgumentException iae) {
Options.raiseErrorMsg(iae, 0);
System.out.println(Options.getHelpMsg()[0]);
System.out.println(" " +
"java -jar <jar_file> [-h|-V|-cr]");
Expand All @@ -46,25 +60,16 @@ else if (args.length > 1) {

switch (Options.getOptions(arg1)) {
case VERSION:
System.out.print(XML.getProperty("programName") + " " +
XML.getProperty("version") + "-");
System.out.print(XML.getProperty("releaseType"));
String pkgName = String.format(" <%s>", XML.getProperty("packageName"));

if (!XML.getProperty("releaseType").equals("release"))
System.out.print("." + XML.getProperty("betaNum"));

System.out.printf(" <%s>%s", XML.getProperty("packageName"), System.lineSeparator());
System.out.println(programVersion + pkgName);
break;

case HELP:
System.out.print(XML.getProperty("programName") + " " + XML.getProperty("version"));

if (!XML.getProperty("releaseType").equals("release")) {
System.out.println("-" + XML.getProperty("releaseType") + "." + XML.getProperty("betaNum"));
} else {
System.out.print(System.lineSeparator());
}
String lines = System.lineSeparator();
for (byte i = 0; i < (byte) programVersion.length(); i++) lines += "-";

System.out.println(programVersion + lines + System.lineSeparator());
for (String s : Options.getHelpMsg()) System.out.println(s);
break;

Expand All @@ -73,4 +78,21 @@ else if (args.length > 1) {
break;
}
}

private static String getVersion() {
String ver = XML.getProperty("version");

// Only retrieve the release type if not release and stable release
if (!XML.getProperty("releaseType").equals("release") ||
!XML.getProperty("releaseType").equals("stable")) {
ver += "-" + XML.getProperty("releaseType");

// This will only retrieve a non-zero beta number
if (XML.getProperty("betaNum").equals("0")) {
ver += "." + XML.getProperty("betaNum");
}
}

return ver;
}
}