Changed license to CC0
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / commandline / parameterparser / Parameter.java
index d55407b..c9023a4 100755 (executable)
@@ -1,23 +1,25 @@
 /*
- * Svjatoslav Commons - shared library of common functionality.
- * Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
  */
-
 package eu.svjatoslav.commons.commandline.parameterparser;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 
 public abstract class Parameter<T, I extends Parameter> {
 
-    public String description;
-    public final ArrayList<String> arguments = new ArrayList<>();
-    ArgumentCount argumentCount;
-    private final ArrayList<String> aliases = new ArrayList<>();
+    /**
+     * Purpose of this argument, like: input image path, compression level, etc...
+     *
+     * Note: for describing argument type (file, integer, ...) there is {@link #describeFormat()}.
+     */
+    public final String description;
+
+    public final List<String> arguments = new ArrayList<>();
+    final ArgumentCount argumentCount;
+    private final List<String> aliases = new ArrayList<>();
     /**
      * Indicates that at least one argument is mandatory for this parameter.
      */
@@ -52,7 +54,7 @@ public abstract class Parameter<T, I extends Parameter> {
         // save aliases
         Collections.addAll(aliases, aliasArray);
 
-        return (I)this;
+        return (I) this;
     }
 
     /**
@@ -92,7 +94,10 @@ public abstract class Parameter<T, I extends Parameter> {
     }
 
     /**
-     * @return Single line argument type description.
+     * @return Single line argument type description. If argument type should be file,
+     * date, integer, regular expression, etc..
+     *
+     * Note: for argument purpose description there is {@link #description}
      */
     public abstract String describeFormat();
 
@@ -116,7 +121,11 @@ public abstract class Parameter<T, I extends Parameter> {
         // first line
         buffer.append(getAliases());
         if (!argumentCount.equals(ArgumentCount.NONE)) {
-            buffer.append(" (" + describeFormat() + ")");
+            buffer
+                    .append(" (")
+                    .append(isMandatory() ? "mandatory, " : "")
+                    .append(describeFormat())
+                    .append(")");
 
             if (argumentCount.equals(ArgumentCount.MULTI))
                 buffer.append("...");
@@ -182,7 +191,7 @@ public abstract class Parameter<T, I extends Parameter> {
     @SuppressWarnings("unchecked")
     public I setMandatory() {
         mandatory = true;
-        return (I)this;
+        return (I) this;
     }
 
     /**