Initial commit
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sat, 25 Jun 2022 23:31:25 +0000 (02:31 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sat, 25 Jun 2022 23:31:25 +0000 (02:31 +0300)
22 files changed:
.gitignore [new file with mode: 0755]
COPYING [new file with mode: 0644]
doc/index.html [new file with mode: 0644]
doc/index.org [new file with mode: 0644]
pom.xml [new file with mode: 0644]
src/main/java/eu/svjatoslav/commons/cli_helper/CLIHelper.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/ArgumentCount.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/Parameter.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/Parser.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/DirectoryParameter.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/DirectoryParameters.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/ExistenceType.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/FileParameter.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/FileParameters.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/IntegerParameter.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/NullParameter.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/StringParameter.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/StringParameters.java [new file with mode: 0644]
src/test/java/eu/svjatoslav/commons/cli_helper/parameter_parser/ParserTest.java [new file with mode: 0755]
tools/commit and push [new file with mode: 0755]
tools/open with IntelliJ IDEA [new file with mode: 0755]
tools/update web site [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100755 (executable)
index 0000000..aea84ec
--- /dev/null
@@ -0,0 +1,7 @@
+/.settings/
+/.project
+/.classpath
+/target/
+/doc/apidocs/
+/.idea/
+/*.iml
diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..0e259d4
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,121 @@
+Creative Commons Legal Code
+
+CC0 1.0 Universal
+
+    CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
+    LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
+    ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
+    INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
+    REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
+    PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
+    THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
+    HEREUNDER.
+
+Statement of Purpose
+
+The laws of most jurisdictions throughout the world automatically confer
+exclusive Copyright and Related Rights (defined below) upon the creator
+and subsequent owner(s) (each and all, an "owner") of an original work of
+authorship and/or a database (each, a "Work").
+
+Certain owners wish to permanently relinquish those rights to a Work for
+the purpose of contributing to a commons of creative, cultural and
+scientific works ("Commons") that the public can reliably and without fear
+of later claims of infringement build upon, modify, incorporate in other
+works, reuse and redistribute as freely as possible in any form whatsoever
+and for any purposes, including without limitation commercial purposes.
+These owners may contribute to the Commons to promote the ideal of a free
+culture and the further production of creative, cultural and scientific
+works, or to gain reputation or greater distribution for their Work in
+part through the use and efforts of others.
+
+For these and/or other purposes and motivations, and without any
+expectation of additional consideration or compensation, the person
+associating CC0 with a Work (the "Affirmer"), to the extent that he or she
+is an owner of Copyright and Related Rights in the Work, voluntarily
+elects to apply CC0 to the Work and publicly distribute the Work under its
+terms, with knowledge of his or her Copyright and Related Rights in the
+Work and the meaning and intended legal effect of CC0 on those rights.
+
+1. Copyright and Related Rights. A Work made available under CC0 may be
+protected by copyright and related or neighboring rights ("Copyright and
+Related Rights"). Copyright and Related Rights include, but are not
+limited to, the following:
+
+  i. the right to reproduce, adapt, distribute, perform, display,
+     communicate, and translate a Work;
+ ii. moral rights retained by the original author(s) and/or performer(s);
+iii. publicity and privacy rights pertaining to a person's image or
+     likeness depicted in a Work;
+ iv. rights protecting against unfair competition in regards to a Work,
+     subject to the limitations in paragraph 4(a), below;
+  v. rights protecting the extraction, dissemination, use and reuse of data
+     in a Work;
+ vi. database rights (such as those arising under Directive 96/9/EC of the
+     European Parliament and of the Council of 11 March 1996 on the legal
+     protection of databases, and under any national implementation
+     thereof, including any amended or successor version of such
+     directive); and
+vii. other similar, equivalent or corresponding rights throughout the
+     world based on applicable law or treaty, and any national
+     implementations thereof.
+
+2. Waiver. To the greatest extent permitted by, but not in contravention
+of, applicable law, Affirmer hereby overtly, fully, permanently,
+irrevocably and unconditionally waives, abandons, and surrenders all of
+Affirmer's Copyright and Related Rights and associated claims and causes
+of action, whether now known or unknown (including existing as well as
+future claims and causes of action), in the Work (i) in all territories
+worldwide, (ii) for the maximum duration provided by applicable law or
+treaty (including future time extensions), (iii) in any current or future
+medium and for any number of copies, and (iv) for any purpose whatsoever,
+including without limitation commercial, advertising or promotional
+purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
+member of the public at large and to the detriment of Affirmer's heirs and
+successors, fully intending that such Waiver shall not be subject to
+revocation, rescission, cancellation, termination, or any other legal or
+equitable action to disrupt the quiet enjoyment of the Work by the public
+as contemplated by Affirmer's express Statement of Purpose.
+
+3. Public License Fallback. Should any part of the Waiver for any reason
+be judged legally invalid or ineffective under applicable law, then the
+Waiver shall be preserved to the maximum extent permitted taking into
+account Affirmer's express Statement of Purpose. In addition, to the
+extent the Waiver is so judged Affirmer hereby grants to each affected
+person a royalty-free, non transferable, non sublicensable, non exclusive,
+irrevocable and unconditional license to exercise Affirmer's Copyright and
+Related Rights in the Work (i) in all territories worldwide, (ii) for the
+maximum duration provided by applicable law or treaty (including future
+time extensions), (iii) in any current or future medium and for any number
+of copies, and (iv) for any purpose whatsoever, including without
+limitation commercial, advertising or promotional purposes (the
+"License"). The License shall be deemed effective as of the date CC0 was
+applied by Affirmer to the Work. Should any part of the License for any
+reason be judged legally invalid or ineffective under applicable law, such
+partial invalidity or ineffectiveness shall not invalidate the remainder
+of the License, and in such case Affirmer hereby affirms that he or she
+will not (i) exercise any of his or her remaining Copyright and Related
+Rights in the Work or (ii) assert any associated claims and causes of
+action with respect to the Work, in either case contrary to Affirmer's
+express Statement of Purpose.
+
+4. Limitations and Disclaimers.
+
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
+    surrendered, licensed or otherwise affected by this document.
+ b. Affirmer offers the Work as-is and makes no representations or
+    warranties of any kind concerning the Work, express, implied,
+    statutory or otherwise, including without limitation warranties of
+    title, merchantability, fitness for a particular purpose, non
+    infringement, or the absence of latent or other defects, accuracy, or
+    the present or absence of errors, whether or not discoverable, all to
+    the greatest extent permissible under applicable law.
+ c. Affirmer disclaims responsibility for clearing rights of other persons
+    that may apply to the Work or any use thereof, including without
+    limitation any person's Copyright and Related Rights in the Work.
+    Further, Affirmer disclaims responsibility for obtaining any necessary
+    consents, permissions or other rights required for any use of the
+    Work.
+ d. Affirmer understands and acknowledges that Creative Commons is not a
+    party to this document and has no duty or obligation with respect to
+    this CC0 or use of the Work.
diff --git a/doc/index.html b/doc/index.html
new file mode 100644 (file)
index 0000000..669f211
--- /dev/null
@@ -0,0 +1,321 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+<!-- 2022-06-26 Sun 02:29 -->
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1" />
+<title>CLI Helper - library to help implementing commandline interfaces</title>
+<meta name="author" content="Svjatoslav Agejenko" />
+<meta name="generator" content="Org Mode" />
+<style>
+  #content { max-width: 60em; margin: auto; }
+  .title  { text-align: center;
+             margin-bottom: .2em; }
+  .subtitle { text-align: center;
+              font-size: medium;
+              font-weight: bold;
+              margin-top:0; }
+  .todo   { font-family: monospace; color: red; }
+  .done   { font-family: monospace; color: green; }
+  .priority { font-family: monospace; color: orange; }
+  .tag    { background-color: #eee; font-family: monospace;
+            padding: 2px; font-size: 80%; font-weight: normal; }
+  .timestamp { color: #bebebe; }
+  .timestamp-kwd { color: #5f9ea0; }
+  .org-right  { margin-left: auto; margin-right: 0px;  text-align: right; }
+  .org-left   { margin-left: 0px;  margin-right: auto; text-align: left; }
+  .org-center { margin-left: auto; margin-right: auto; text-align: center; }
+  .underline { text-decoration: underline; }
+  #postamble p, #preamble p { font-size: 90%; margin: .2em; }
+  p.verse { margin-left: 3%; }
+  pre {
+    border: 1px solid #e6e6e6;
+    border-radius: 3px;
+    background-color: #f2f2f2;
+    padding: 8pt;
+    font-family: monospace;
+    overflow: auto;
+    margin: 1.2em;
+  }
+  pre.src {
+    position: relative;
+    overflow: auto;
+  }
+  pre.src:before {
+    display: none;
+    position: absolute;
+    top: -8px;
+    right: 12px;
+    padding: 3px;
+    color: #555;
+    background-color: #f2f2f299;
+  }
+  pre.src:hover:before { display: inline; margin-top: 14px;}
+  /* Languages per Org manual */
+  pre.src-asymptote:before { content: 'Asymptote'; }
+  pre.src-awk:before { content: 'Awk'; }
+  pre.src-authinfo::before { content: 'Authinfo'; }
+  pre.src-C:before { content: 'C'; }
+  /* pre.src-C++ doesn't work in CSS */
+  pre.src-clojure:before { content: 'Clojure'; }
+  pre.src-css:before { content: 'CSS'; }
+  pre.src-D:before { content: 'D'; }
+  pre.src-ditaa:before { content: 'ditaa'; }
+  pre.src-dot:before { content: 'Graphviz'; }
+  pre.src-calc:before { content: 'Emacs Calc'; }
+  pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
+  pre.src-fortran:before { content: 'Fortran'; }
+  pre.src-gnuplot:before { content: 'gnuplot'; }
+  pre.src-haskell:before { content: 'Haskell'; }
+  pre.src-hledger:before { content: 'hledger'; }
+  pre.src-java:before { content: 'Java'; }
+  pre.src-js:before { content: 'Javascript'; }
+  pre.src-latex:before { content: 'LaTeX'; }
+  pre.src-ledger:before { content: 'Ledger'; }
+  pre.src-lisp:before { content: 'Lisp'; }
+  pre.src-lilypond:before { content: 'Lilypond'; }
+  pre.src-lua:before { content: 'Lua'; }
+  pre.src-matlab:before { content: 'MATLAB'; }
+  pre.src-mscgen:before { content: 'Mscgen'; }
+  pre.src-ocaml:before { content: 'Objective Caml'; }
+  pre.src-octave:before { content: 'Octave'; }
+  pre.src-org:before { content: 'Org mode'; }
+  pre.src-oz:before { content: 'OZ'; }
+  pre.src-plantuml:before { content: 'Plantuml'; }
+  pre.src-processing:before { content: 'Processing.js'; }
+  pre.src-python:before { content: 'Python'; }
+  pre.src-R:before { content: 'R'; }
+  pre.src-ruby:before { content: 'Ruby'; }
+  pre.src-sass:before { content: 'Sass'; }
+  pre.src-scheme:before { content: 'Scheme'; }
+  pre.src-screen:before { content: 'Gnu Screen'; }
+  pre.src-sed:before { content: 'Sed'; }
+  pre.src-sh:before { content: 'shell'; }
+  pre.src-sql:before { content: 'SQL'; }
+  pre.src-sqlite:before { content: 'SQLite'; }
+  /* additional languages in org.el's org-babel-load-languages alist */
+  pre.src-forth:before { content: 'Forth'; }
+  pre.src-io:before { content: 'IO'; }
+  pre.src-J:before { content: 'J'; }
+  pre.src-makefile:before { content: 'Makefile'; }
+  pre.src-maxima:before { content: 'Maxima'; }
+  pre.src-perl:before { content: 'Perl'; }
+  pre.src-picolisp:before { content: 'Pico Lisp'; }
+  pre.src-scala:before { content: 'Scala'; }
+  pre.src-shell:before { content: 'Shell Script'; }
+  pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
+  /* additional language identifiers per "defun org-babel-execute"
+       in ob-*.el */
+  pre.src-cpp:before  { content: 'C++'; }
+  pre.src-abc:before  { content: 'ABC'; }
+  pre.src-coq:before  { content: 'Coq'; }
+  pre.src-groovy:before  { content: 'Groovy'; }
+  /* additional language identifiers from org-babel-shell-names in
+     ob-shell.el: ob-shell is the only babel language using a lambda to put
+     the execution function name together. */
+  pre.src-bash:before  { content: 'bash'; }
+  pre.src-csh:before  { content: 'csh'; }
+  pre.src-ash:before  { content: 'ash'; }
+  pre.src-dash:before  { content: 'dash'; }
+  pre.src-ksh:before  { content: 'ksh'; }
+  pre.src-mksh:before  { content: 'mksh'; }
+  pre.src-posh:before  { content: 'posh'; }
+  /* Additional Emacs modes also supported by the LaTeX listings package */
+  pre.src-ada:before { content: 'Ada'; }
+  pre.src-asm:before { content: 'Assembler'; }
+  pre.src-caml:before { content: 'Caml'; }
+  pre.src-delphi:before { content: 'Delphi'; }
+  pre.src-html:before { content: 'HTML'; }
+  pre.src-idl:before { content: 'IDL'; }
+  pre.src-mercury:before { content: 'Mercury'; }
+  pre.src-metapost:before { content: 'MetaPost'; }
+  pre.src-modula-2:before { content: 'Modula-2'; }
+  pre.src-pascal:before { content: 'Pascal'; }
+  pre.src-ps:before { content: 'PostScript'; }
+  pre.src-prolog:before { content: 'Prolog'; }
+  pre.src-simula:before { content: 'Simula'; }
+  pre.src-tcl:before { content: 'tcl'; }
+  pre.src-tex:before { content: 'TeX'; }
+  pre.src-plain-tex:before { content: 'Plain TeX'; }
+  pre.src-verilog:before { content: 'Verilog'; }
+  pre.src-vhdl:before { content: 'VHDL'; }
+  pre.src-xml:before { content: 'XML'; }
+  pre.src-nxml:before { content: 'XML'; }
+  /* add a generic configuration mode; LaTeX export needs an additional
+     (add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
+  pre.src-conf:before { content: 'Configuration File'; }
+
+  table { border-collapse:collapse; }
+  caption.t-above { caption-side: top; }
+  caption.t-bottom { caption-side: bottom; }
+  td, th { vertical-align:top;  }
+  th.org-right  { text-align: center;  }
+  th.org-left   { text-align: center;   }
+  th.org-center { text-align: center; }
+  td.org-right  { text-align: right;  }
+  td.org-left   { text-align: left;   }
+  td.org-center { text-align: center; }
+  dt { font-weight: bold; }
+  .footpara { display: inline; }
+  .footdef  { margin-bottom: 1em; }
+  .figure { padding: 1em; }
+  .figure p { text-align: center; }
+  .equation-container {
+    display: table;
+    text-align: center;
+    width: 100%;
+  }
+  .equation {
+    vertical-align: middle;
+  }
+  .equation-label {
+    display: table-cell;
+    text-align: right;
+    vertical-align: middle;
+  }
+  .inlinetask {
+    padding: 10px;
+    border: 2px solid gray;
+    margin: 10px;
+    background: #ffffcc;
+  }
+  #org-div-home-and-up
+   { text-align: right; font-size: 70%; white-space: nowrap; }
+  textarea { overflow-x: auto; }
+  .linenr { font-size: smaller }
+  .code-highlighted { background-color: #ffff00; }
+  .org-info-js_info-navigation { border-style: none; }
+  #org-info-js_console-label
+    { font-size: 10px; font-weight: bold; white-space: nowrap; }
+  .org-info-js_search-highlight
+    { background-color: #ffff00; color: #000000; font-weight: bold; }
+  .org-svg { }
+</style>
+<link rel="stylesheet" type="text/css" href="https://thomasf.github.io/solarized-css/solarized-dark.min.css" />
+</head>
+<body>
+<div id="content" class="content">
+<h1 class="title">CLI Helper - library to help implementing commandline interfaces</h1>
+<div id="table-of-contents" role="doc-toc">
+<h2>Table of Contents</h2>
+<div id="text-table-of-contents" role="doc-toc">
+<ul>
+<li><a href="#org06fe663">1. General</a>
+<ul>
+<li><a href="#orgb4ac6b6">1.1. Source code</a></li>
+</ul>
+</li>
+<li><a href="#orgd86fbab">2. Library contents</a></li>
+<li><a href="#orge31c7b8">3. Usage</a></li>
+</ul>
+</div>
+</div>
+
+<div id="outline-container-org06fe663" class="outline-2">
+<h2 id="org06fe663"><span class="section-number-2">1.</span> General</h2>
+<div class="outline-text-2" id="text-1">
+<ul class="org-ul">
+<li>This program is free software: released under Creative Commons Zero
+(CC0) license</li>
+
+<li>Program author:
+<ul class="org-ul">
+<li>Svjatoslav Agejenko</li>
+<li>Homepage: <a href="https://svjatoslav.eu">https://svjatoslav.eu</a></li>
+<li>Email: <a href="mailto://svjatoslav@svjatoslav.eu">mailto://svjatoslav@svjatoslav.eu</a></li>
+</ul></li>
+
+<li><a href="https://www.svjatoslav.eu/projects/">Other software projects hosted at svjatoslav.eu</a></li>
+</ul>
+</div>
+
+<div id="outline-container-orgb4ac6b6" class="outline-3">
+<h3 id="orgb4ac6b6"><span class="section-number-3">1.1.</span> Source code</h3>
+<div class="outline-text-3" id="text-1-1">
+<ul class="org-ul">
+<li><a href="https://www2.svjatoslav.eu/gitweb/?p=cli-helper.git;a=snapshot;h=HEAD;sf=tgz">Download latest snapshot in TAR GZ format</a></li>
+
+<li><a href="https://www2.svjatoslav.eu/gitweb/?p=cli-helper.git;a=summary">Browse Git repository online</a></li>
+
+<li><p>
+Clone Git repository using command:
+</p>
+<pre class="example">
+git clone https://www2.svjatoslav.eu/git/cli-helper.git
+</pre></li>
+
+<li>See <a href="https://www3.svjatoslav.eu/projects/cli-helper/apidocs/">JavaDoc</a></li>
+</ul>
+</div>
+</div>
+</div>
+
+<div id="outline-container-orgd86fbab" class="outline-2">
+<h2 id="orgd86fbab"><span class="section-number-2">2.</span> Library contents</h2>
+<div class="outline-text-2" id="text-2">
+<ul class="org-ul">
+<li>See <a href="https://www3.svjatoslav.eu/projects/svjatoslav_commons/apidocs/">JavaDoc</a>.</li>
+
+<li><p>
+Commandline Interface helper
+</p>
+<pre class="example">
+eu.svjatoslav.commons.cli_helper.CLIHelper
+</pre></li>
+
+<li><p>
+Commandline arguments parser and validator.
+</p>
+<pre class="example">
+eu.svjatoslav.commons.cli_helper.parameter_parser
+</pre></li>
+</ul>
+</div>
+</div>
+
+<div id="outline-container-orge31c7b8" class="outline-2">
+<h2 id="orge31c7b8"><span class="section-number-2">3.</span> Usage</h2>
+<div class="outline-text-2" id="text-3">
+<p>
+Instructions to embed svjatoslav-commons in your project as a library:
+</p>
+
+<p>
+Maven pom.xml file snippet:
+</p>
+
+<div class="org-src-container">
+<pre class="src src-xml">&lt;<span style="color: #A6E22E;">dependencies</span>&gt;
+    ...
+    &lt;<span style="color: #A6E22E;">dependency</span>&gt;
+        &lt;<span style="color: #A6E22E;">groupId</span>&gt;eu.svjatoslav&lt;/<span style="color: #A6E22E;">groupId</span>&gt;
+        &lt;<span style="color: #A6E22E;">artifactId</span>&gt;cli-helper&lt;/<span style="color: #A6E22E;">artifactId</span>&gt;
+        &lt;<span style="color: #A6E22E;">version</span>&gt;1.0&lt;/<span style="color: #A6E22E;">version</span>&gt;
+    &lt;/<span style="color: #A6E22E;">dependency</span>&gt;
+    ...
+&lt;/<span style="color: #A6E22E;">dependencies</span>&gt;
+
+
+&lt;<span style="color: #A6E22E;">repositories</span>&gt;
+    ...
+    &lt;<span style="color: #A6E22E;">repository</span>&gt;
+        &lt;<span style="color: #A6E22E;">id</span>&gt;svjatoslav.eu&lt;/<span style="color: #A6E22E;">id</span>&gt;
+        &lt;<span style="color: #A6E22E;">name</span>&gt;Svjatoslav repository&lt;/<span style="color: #A6E22E;">name</span>&gt;
+        &lt;<span style="color: #A6E22E;">url</span>&gt;http://www2.svjatoslav.eu/maven/&lt;/<span style="color: #A6E22E;">url</span>&gt;
+    &lt;/<span style="color: #A6E22E;">repository</span>&gt;
+    ...
+&lt;/<span style="color: #A6E22E;">repositories</span>&gt;
+</pre>
+</div>
+</div>
+</div>
+</div>
+<div id="postamble" class="status">
+<p class="author">Author: Svjatoslav Agejenko</p>
+<p class="date">Created: 2022-06-26 Sun 02:29</p>
+<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
+</div>
+</body>
+</html>
diff --git a/doc/index.org b/doc/index.org
new file mode 100644 (file)
index 0000000..64f7146
--- /dev/null
@@ -0,0 +1,59 @@
+#+TITLE: CLI Helper - library to help implementing commandline interfaces
+
+* General
+- This program is free software: released under Creative Commons Zero
+  (CC0) license
+
+- Program author:
+  - Svjatoslav Agejenko
+  - Homepage: https://svjatoslav.eu
+  - Email: mailto://svjatoslav@svjatoslav.eu
+
+- [[https://www.svjatoslav.eu/projects/][Other software projects hosted at svjatoslav.eu]]
+
+** Source code
+- [[https://www2.svjatoslav.eu/gitweb/?p=cli-helper.git;a=snapshot;h=HEAD;sf=tgz][Download latest snapshot in TAR GZ format]]
+
+- [[https://www2.svjatoslav.eu/gitweb/?p=cli-helper.git;a=summary][Browse Git repository online]]
+
+- Clone Git repository using command:
+  : git clone https://www2.svjatoslav.eu/git/cli-helper.git
+
+- See [[https://www3.svjatoslav.eu/projects/cli-helper/apidocs/][JavaDoc]]
+
+* Library contents
+- See [[https://www3.svjatoslav.eu/projects/svjatoslav_commons/apidocs/][JavaDoc]].
+
+- Commandline Interface helper
+  : eu.svjatoslav.commons.cli_helper.CLIHelper
+
+- Commandline arguments parser and validator.
+  : eu.svjatoslav.commons.cli_helper.parameter_parser
+
+* Usage
+Instructions to embed svjatoslav-commons in your project as a library:
+
+Maven pom.xml file snippet:
+
+#+BEGIN_SRC xml
+<dependencies>
+    ...
+    <dependency>
+        <groupId>eu.svjatoslav</groupId>
+        <artifactId>cli-helper</artifactId>
+        <version>1.0</version>
+    </dependency>
+    ...
+</dependencies>
+
+
+<repositories>
+    ...
+    <repository>
+        <id>svjatoslav.eu</id>
+        <name>Svjatoslav repository</name>
+        <url>http://www2.svjatoslav.eu/maven/</url>
+    </repository>
+    ...
+</repositories>
+#+END_SRC
diff --git a/pom.xml b/pom.xml
new file mode 100644 (file)
index 0000000..60d9cd4
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,125 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>eu.svjatoslav</groupId>
+    <artifactId>cli-helper</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+    <name>CLI helper</name>
+    <description>Helper library for implementing commandline interface</description>
+    <url>http://www2.svjatoslav.eu/gitbrowse/cli-helper/doc/index.html</url>
+
+    <organization>
+        <name>svjatoslav.eu</name>
+        <url>http://svjatoslav.eu</url>
+    </organization>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <source>8</source>
+                    <target>8</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-source-plugin</artifactId>
+                <version>2.2.1</version>
+                <executions>
+                    <execution>
+                        <id>attach-sources</id>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <version>3.1.1</version>
+                <executions>
+                    <execution>
+                        <id>attach-javadocs</id>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+<!--                <configuration>-->
+<!--                    &lt;!&ndash; workaround for https://bugs.openjdk.java.net/browse/JDK-8212233 &ndash;&gt;-->
+<!--                    <javaApiLinks>-->
+<!--                        <property>-->
+<!--                            <name>foo</name>-->
+<!--                            <value>bar</value>-->
+<!--                        </property>-->
+<!--                    </javaApiLinks>-->
+<!--                    &lt;!&ndash; Workaround for https://stackoverflow.com/questions/49472783/maven-is-unable-to-find-javadoc-command &ndash;&gt;-->
+<!--                    <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>-->
+<!--                </configuration>-->
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-release-plugin</artifactId>
+                <version>2.5.2</version>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.apache.maven.scm</groupId>
+                        <artifactId>maven-scm-provider-gitexe</artifactId>
+                        <version>1.9.4</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
+
+        </plugins>
+
+        <extensions>
+            <extension>
+                <groupId>org.apache.maven.wagon</groupId>
+                <artifactId>wagon-ssh-external</artifactId>
+                <version>2.6</version>
+            </extension>
+        </extensions>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.13.2</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <distributionManagement>
+        <snapshotRepository>
+            <id>svjatoslav.eu</id>
+            <name>svjatoslav.eu</name>
+            <url>scpexe://svjatoslav.eu:10006/srv/maven</url>
+        </snapshotRepository>
+        <repository>
+            <id>svjatoslav.eu</id>
+            <name>svjatoslav.eu</name>
+            <url>scpexe://svjatoslav.eu:10006/srv/maven</url>
+        </repository>
+    </distributionManagement>
+
+    <scm>
+        <connection>scm:git:ssh://n0@svjatoslav.eu:10006/home/n0/git/cli-helper.git</connection>
+        <developerConnection>scm:git:ssh://n0@svjatoslav.eu:10006/home/n0/git/cli-helper.git</developerConnection>
+        <tag>HEAD</tag>
+    </scm>
+
+</project>
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/CLIHelper.java b/src/main/java/eu/svjatoslav/commons/cli_helper/CLIHelper.java
new file mode 100755 (executable)
index 0000000..184585b
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * Command-line interface helper.
+ */
+public class CLIHelper {
+
+    /**
+     * Ask boolean value from user on command-line.
+     *
+     * @param prompt to show to the user
+     * @return <code>true</code> is user answered affirmative.
+     */
+    public static boolean askBoolean(final String prompt) {
+
+        final BufferedReader br = new BufferedReader(new InputStreamReader(
+                System.in));
+
+        while (true)
+            try {
+                System.out.print(prompt);
+
+                String line = br.readLine();
+                if (line != null) {
+                    final String userInput = line.toLowerCase();
+
+                    if ("y".equals(userInput) || "yes".equals(userInput)
+                            || "true".equals(userInput))
+                        return true;
+
+                    if ("n".equals(userInput) || "no".equals(userInput)
+                            || "false".equals(userInput))
+                        return false;
+                }
+                System.out
+                        .println("Invalid input. You shall enter y/yes/true or n/no/false.");
+            } catch (final IOException ioe) {
+                ioe.printStackTrace();
+            }
+    }
+
+    /**
+     * Ask numerical long value from user on command-line.
+     *
+     * @param prompt to show to the user
+     * @return value given by user
+     */
+    public static long askLong(final String prompt) {
+
+        final BufferedReader br = new BufferedReader(new InputStreamReader(
+                System.in));
+
+        while (true) {
+            System.out.print(prompt);
+
+            try {
+                final String userInput = br.readLine();
+
+                try {
+                    return Long.parseLong(userInput);
+                } catch (final NumberFormatException e) {
+                    System.out.println("\nError: You shall enter an integer.");
+                }
+            } catch (final IOException ioe) {
+                ioe.printStackTrace();
+            }
+
+        }
+    }
+
+    /**
+     * Ask string value from user on command-line.
+     *
+     * @param prompt to show to the user
+     * @return value given by the user
+     */
+    public static String askString(final String prompt) {
+
+        final BufferedReader br = new BufferedReader(new InputStreamReader(
+                System.in));
+
+        while (true) {
+            System.out.print(prompt);
+
+            try {
+                return br.readLine();
+            } catch (final IOException ioe) {
+                ioe.printStackTrace();
+            }
+
+        }
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/ArgumentCount.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/ArgumentCount.java
new file mode 100755 (executable)
index 0000000..1d830a3
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser;
+
+public enum ArgumentCount {
+
+    NONE, // parameter has no arguments
+    SINGLE, // parameter has one argument
+    MULTI // parameter can have multiple arguments
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/Parameter.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/Parameter.java
new file mode 100755 (executable)
index 0000000..92c5c81
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public abstract class Parameter<T, I extends Parameter> {
+
+    /**
+     * 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.
+     */
+    protected boolean mandatory;
+    /**
+     * If this parameter was present in the commandline, then this boolean will
+     * be set to <code>true</code>.
+     */
+    private boolean specified;
+
+    public Parameter(final boolean mandatory,
+                     final ArgumentCount argumentCount, final String description,
+                     final String... aliases2) {
+
+        this.mandatory = mandatory;
+        this.description = description;
+        this.argumentCount = argumentCount;
+
+        // save aliases
+        Collections.addAll(aliases, aliases2);
+
+    }
+
+    public Parameter(final String description, final ArgumentCount argumentCount) {
+        this.description = description;
+        this.argumentCount = argumentCount;
+    }
+
+    @SuppressWarnings("unchecked")
+    public I addAliases(final String... aliasArray) {
+
+        // save aliases
+        Collections.addAll(aliases, aliasArray);
+
+        return (I) this;
+    }
+
+    /**
+     * @param argumentString argument to add
+     * @return <code>true</code> if no errors were found. <code>false</code>
+     * otherwise.
+     */
+    public boolean addArgument(final String argumentString) {
+        // check if arguments are allowed for this parameter
+        if (argumentCount.equals(ArgumentCount.NONE)) {
+            System.out
+                    .println("Error! No arguments are allowed for parameters: "
+                            + getAliases());
+            return false;
+        }
+
+        // check if multiple arguments are allowed
+        if ((arguments.size() > 0)
+                && (argumentCount.equals(ArgumentCount.SINGLE))) {
+            System.out
+                    .println("Error! Only single argument is allowed for parameters: "
+                            + getAliases());
+            return false;
+        }
+
+        if (!validate(argumentString)) {
+
+            System.out.println("Error! Invalid argument \"" + argumentString
+                    + "\". It shall be " + describeFormat() + ".");
+            return false;
+
+        }
+
+        arguments.add(argumentString);
+
+        return true;
+    }
+
+    /**
+     * @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();
+
+    public String getAliases() {
+        final StringBuilder buffer = new StringBuilder();
+
+        for (final String alias : aliases) {
+
+            if (buffer.length() > 0)
+                buffer.append(", ");
+
+            buffer.append(alias);
+        }
+
+        return buffer.toString();
+    }
+
+    public String getHelp() {
+        final StringBuilder buffer = new StringBuilder();
+
+        // first line
+        buffer.append(getAliases());
+        if (!argumentCount.equals(ArgumentCount.NONE)) {
+            buffer
+                    .append(" (")
+                    .append(isMandatory() ? "mandatory, " : "")
+                    .append(describeFormat())
+                    .append(")");
+
+            if (argumentCount.equals(ArgumentCount.MULTI))
+                buffer.append("...");
+        }
+        buffer.append("\n");
+
+        // second line
+        buffer.append("    " + description + "\n");
+
+        return buffer.toString();
+    }
+
+    public abstract T getValue();
+
+    public boolean isMandatory() {
+        return mandatory;
+    }
+
+    /**
+     * @return the parameterSpecified
+     */
+    public boolean isSpecified() {
+        return specified;
+    }
+
+    /**
+     * @param specified the parameterSpecified to set
+     */
+    protected void setSpecified(final boolean specified) {
+        this.specified = specified;
+    }
+
+    /**
+     * @param alias alias to check against
+     * @return <code>true</code> if given alias is registered for this
+     * parameter.
+     */
+    public boolean matchesAlias(final String alias) {
+        return aliases.contains(alias);
+
+    }
+
+    /**
+     * Notifies this parameter that no more arguments will follow. This gives
+     * parameter chance to verify if this is ok.
+     *
+     * @return <code>true</code> if no errors were found. <code>false</code>
+     * otherwise.
+     */
+    public boolean noMoreArguments() {
+
+        if ((!argumentCount.equals(ArgumentCount.NONE))
+                && (arguments.isEmpty())) {
+
+            System.out.println("Error! " + getAliases()
+                    + " require at least one following argument.");
+
+            return false;
+        }
+        return true;
+    }
+
+    @SuppressWarnings("unchecked")
+    public I setMandatory() {
+        mandatory = true;
+        return (I) this;
+    }
+
+    /**
+     * @param value value to validate
+     * @return <code>true</code> if value is correct, <code>false</code>
+     * otherwise.
+     */
+    public abstract boolean validate(String value);
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/Parser.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/Parser.java
new file mode 100755 (executable)
index 0000000..639be0f
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser;
+
+import java.util.ArrayList;
+
+/**
+ * Single commandline parameter can have any amount of arguments.
+ */
+public class Parser {
+
+    private final ArrayList<Parameter<?, ? extends Parameter>> parameters = new ArrayList<>();
+
+    public <E extends Parameter> E add(final E parameter) {
+        parameters.add(parameter);
+        return parameter;
+    }
+
+    /**
+     * @return <code>true</code> if no errors were found. <code>false</code>
+     * otherwise.
+     */
+    private boolean checkMandatoryArgumentsPresent() {
+
+        for (final Parameter parameter : parameters)
+            if (parameter.isMandatory() && (!parameter.isSpecified())) {
+                System.out.println("Error! Mandatory parameter ("
+                        + parameter.getAliases() + ") is not specified.");
+                return false;
+            }
+
+        return true;
+    }
+
+    /**
+     * Return parameter by given alias or <code>null</code> if no parameter
+     * exists for given alias.
+     *
+     * @param alias parameter alias
+     * @return found parameter or <code>null</code> if parameter was not found.
+     */
+    public Parameter findParameterByAlias(final String alias) {
+
+        for (final Parameter parameter : parameters)
+            if (parameter.matchesAlias(alias))
+                return parameter;
+
+        return null;
+    }
+
+    /**
+     * @param args commandline arguments
+     * @return <code>true</code> if no errors were found. <code>false</code>
+     * otherwise.
+     */
+    public boolean parse(final String[] args) {
+
+        Parameter currentParameter = null;
+
+        for (final String argument : args) {
+
+            final Parameter parameterForAlias = findParameterByAlias(argument);
+            if (parameterForAlias == null) {
+                if (currentParameter == null) {
+                    System.out.println("Unknown commandline parameter: "
+                            + argument);
+                    return false;
+                }
+
+                if (!currentParameter.addArgument(argument))
+                    return false;
+
+            } else {
+                if (currentParameter != null)
+                    if (!currentParameter.noMoreArguments())
+                        return false;
+
+                parameterForAlias.setSpecified(true);
+                currentParameter = parameterForAlias;
+            }
+
+        }
+
+        return checkMandatoryArgumentsPresent();
+    }
+
+    public void showHelp() {
+        System.out.println("Available commandline arguments:");
+        for (final Parameter parameter : parameters)
+            System.out.println(parameter.getHelp());
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/DirectoryParameter.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/DirectoryParameter.java
new file mode 100755 (executable)
index 0000000..c76b146
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
+
+import eu.svjatoslav.commons.cli_helper.parameter_parser.ArgumentCount;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.Parameter;
+
+import java.io.File;
+
+public class DirectoryParameter extends Parameter<File, DirectoryParameter> {
+
+    private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
+
+    public DirectoryParameter(final String description) {
+        super(description, ArgumentCount.SINGLE);
+    }
+
+    @Override
+    public java.lang.String describeFormat() {
+        return existenceType.description + " directory";
+    }
+
+    @Override
+    public File getValue() {
+
+        if (arguments.size() != 1)
+            throw new RuntimeException("Parameter " + description
+                    + " shall have exactly 1 argument.");
+
+        return new File(arguments.get(0));
+    }
+
+    public DirectoryParameter mustExist() {
+        existenceType = ExistenceType.MUST_EXIST;
+        return this;
+    }
+
+    public DirectoryParameter mustNotExist() {
+        existenceType = ExistenceType.MUST_NOT_EXIST;
+        return this;
+    }
+
+    @Override
+    public boolean validate(final java.lang.String value) {
+        final File file = new File(value);
+
+        if (existenceType == ExistenceType.MUST_EXIST) {
+            return file.exists() && file.isDirectory();
+        }
+
+        if (existenceType == ExistenceType.MUST_NOT_EXIST) {
+            return !file.exists();
+        }
+
+        if (existenceType == ExistenceType.DOES_NOT_MATTER) {
+            if (file.exists())
+                if (file.isFile())
+                    return false;
+
+            return true;
+        }
+
+        return false;
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/DirectoryParameters.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/DirectoryParameters.java
new file mode 100755 (executable)
index 0000000..0927aaf
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
+
+import eu.svjatoslav.commons.cli_helper.parameter_parser.ArgumentCount;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.Parameter;
+
+import java.io.File;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class DirectoryParameters extends Parameter<List<File>, DirectoryParameters> {
+
+    private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
+
+    public DirectoryParameters(final String description) {
+        super(description, ArgumentCount.MULTI);
+    }
+
+    @Override
+    public String describeFormat() {
+        return existenceType.description + " directories";
+    }
+
+    @Override
+    public List<File> getValue() {
+        return arguments.stream().map(File::new).collect(Collectors.toList());
+    }
+
+    public DirectoryParameters mustExist() {
+        existenceType = ExistenceType.MUST_EXIST;
+        return this;
+    }
+
+    public DirectoryParameters mustNotExist() {
+        existenceType = ExistenceType.MUST_NOT_EXIST;
+        return this;
+    }
+
+    @Override
+    public boolean validate(final String value) {
+        final File file = new File(value);
+
+        if (existenceType == ExistenceType.MUST_EXIST) {
+            return file.exists() && file.isDirectory();
+        }
+
+        if (existenceType == ExistenceType.MUST_NOT_EXIST) {
+            return !file.exists();
+        }
+
+        if (existenceType == ExistenceType.DOES_NOT_MATTER) {
+            if (file.exists())
+                if (file.isFile())
+                    return false;
+
+            return true;
+        }
+
+        return false;
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/ExistenceType.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/ExistenceType.java
new file mode 100755 (executable)
index 0000000..0b6b4bc
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
+
+public enum ExistenceType {
+
+    MUST_EXIST("existing"), MUST_NOT_EXIST("not existing"), DOES_NOT_MATTER("");
+
+    public final String description;
+
+    ExistenceType(final String description) {
+        this.description = description;
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/FileParameter.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/FileParameter.java
new file mode 100755 (executable)
index 0000000..5435bc3
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
+
+import eu.svjatoslav.commons.cli_helper.parameter_parser.ArgumentCount;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.Parameter;
+
+import java.io.File;
+
+public class FileParameter extends Parameter<File, FileParameter> {
+
+    private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
+
+    public FileParameter(final String description) {
+        super(description, ArgumentCount.SINGLE);
+    }
+
+    protected static boolean validateFile(ExistenceType existenceType, String value) {
+        final File file = new File(value);
+
+        if (existenceType == ExistenceType.MUST_EXIST) {
+            return file.exists() && file.isFile();
+        }
+
+        if (existenceType == ExistenceType.MUST_NOT_EXIST) {
+            return !file.exists();
+        }
+
+        if (existenceType == ExistenceType.DOES_NOT_MATTER) {
+            if (file.exists())
+                if (file.isDirectory())
+                    return false;
+
+            return true;
+        }
+
+        return false;
+    }
+
+    @Override
+    public java.lang.String describeFormat() {
+        return existenceType.description + " file";
+    }
+
+    @Override
+    public File getValue() {
+
+        if (arguments.size() != 1)
+            throw new RuntimeException("Parameter " + description
+                    + " shall have exactly 1 argument.");
+
+        return new File(arguments.get(0));
+    }
+
+    public FileParameter mustExist() {
+        existenceType = ExistenceType.MUST_EXIST;
+        return this;
+    }
+
+    public FileParameter mustNotExist() {
+        existenceType = ExistenceType.MUST_NOT_EXIST;
+        return this;
+    }
+
+    @Override
+    public boolean validate(final java.lang.String value) {
+        return validateFile(existenceType, value);
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/FileParameters.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/FileParameters.java
new file mode 100755 (executable)
index 0000000..850114a
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
+
+import eu.svjatoslav.commons.cli_helper.parameter_parser.ArgumentCount;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.Parameter;
+
+import java.io.File;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.FileParameter.validateFile;
+
+public class FileParameters extends Parameter<List<File>, FileParameters> {
+
+    private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
+
+    public FileParameters(final String description) {
+        super(description, ArgumentCount.MULTI);
+    }
+
+    @Override
+    public String describeFormat() {
+        return existenceType.description + " files";
+    }
+
+    @Override
+    public List<File> getValue() {
+        return arguments.stream().map(File::new).collect(Collectors.toList());
+    }
+
+    public FileParameters mustExist() {
+        existenceType = ExistenceType.MUST_EXIST;
+        return this;
+    }
+
+    public FileParameters mustNotExist() {
+        existenceType = ExistenceType.MUST_NOT_EXIST;
+        return this;
+    }
+
+    @Override
+    public boolean validate(final String value) {
+        return validateFile(existenceType, value);
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/IntegerParameter.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/IntegerParameter.java
new file mode 100755 (executable)
index 0000000..130d360
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
+
+import eu.svjatoslav.commons.cli_helper.parameter_parser.ArgumentCount;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.Parameter;
+
+public class IntegerParameter extends Parameter<Integer, IntegerParameter> {
+
+    public IntegerParameter(final String description) {
+        super(description, ArgumentCount.SINGLE);
+    }
+
+    @Override
+    public java.lang.String describeFormat() {
+        return "integer";
+    }
+
+    @Override
+    public Integer getValue() {
+        if (arguments.size() != 1)
+            throw new RuntimeException("Parameter " + description
+                    + " shall have exactly 1 argument.");
+        return Integer.parseInt(arguments.get(0));
+    }
+
+    @Override
+    public boolean validate(final java.lang.String value) {
+        try {
+            java.lang.Integer.valueOf(value);
+            return true;
+        } catch (final NumberFormatException e) {
+            return false;
+        }
+    }
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/NullParameter.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/NullParameter.java
new file mode 100755 (executable)
index 0000000..ca234af
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
+
+import eu.svjatoslav.commons.cli_helper.parameter_parser.ArgumentCount;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.Parameter;
+
+public class NullParameter extends Parameter<Boolean, NullParameter> {
+
+    public NullParameter(final String description) {
+        super(description, ArgumentCount.NONE);
+    }
+
+    @Override
+    public java.lang.String describeFormat() {
+        return "<none>";
+    }
+
+    @Override
+    public Boolean getValue() {
+        return isSpecified();
+    }
+
+    @Override
+    public boolean validate(final java.lang.String value) {
+        return true;
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/StringParameter.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/StringParameter.java
new file mode 100755 (executable)
index 0000000..c5ed383
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
+
+import eu.svjatoslav.commons.cli_helper.parameter_parser.ArgumentCount;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.Parameter;
+
+public class StringParameter extends Parameter<String, StringParameter> {
+
+    public final String defaultValue;
+
+    public StringParameter(final String description) {
+        super(description, ArgumentCount.SINGLE);
+        defaultValue = null;
+    }
+    public StringParameter(final String description, String defaultValue) {
+        super(description, ArgumentCount.SINGLE);
+        this.defaultValue = defaultValue;
+        this.setSpecified(true);
+    }
+
+    @Override
+    public java.lang.String describeFormat() {
+        return "string";
+    }
+
+    @Override
+    public String getValue() {
+
+        if (arguments.isEmpty() && (defaultValue != null)) return defaultValue;
+
+        if (arguments.size() == 1) return arguments.get(0);
+
+        throw new RuntimeException("Parameter " + description
+                + " shall have exactly 1 argument.");
+    }
+
+    @Override
+    public boolean validate(final java.lang.String value) {
+        return true;
+    }
+
+}
diff --git a/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/StringParameters.java b/src/main/java/eu/svjatoslav/commons/cli_helper/parameter_parser/parameter/StringParameters.java
new file mode 100644 (file)
index 0000000..1a3e410
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
+
+import eu.svjatoslav.commons.cli_helper.parameter_parser.ArgumentCount;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.Parameter;
+
+import java.util.List;
+
+public class StringParameters extends Parameter<List<String>, StringParameters> {
+
+    public StringParameters(final String description) {
+        super(description, ArgumentCount.MULTI);
+    }
+
+    @Override
+    public java.lang.String describeFormat() {
+        return "one to many strings";
+    }
+
+    @Override
+    public List<String> getValue() {
+        return arguments;
+    }
+
+    @Override
+    public boolean validate(final java.lang.String value) {
+        return true;
+    }
+
+}
diff --git a/src/test/java/eu/svjatoslav/commons/cli_helper/parameter_parser/ParserTest.java b/src/test/java/eu/svjatoslav/commons/cli_helper/parameter_parser/ParserTest.java
new file mode 100755 (executable)
index 0000000..ab87cae
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser;
+
+import eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.FileParameter;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.StringParameter;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import static org.junit.Assert.*;
+
+public class ParserTest {
+
+    Parser parser;
+
+    @Before
+    public void setUp() {
+        parser = new Parser();
+    }
+
+    @Test
+    public void testParse() throws IOException {
+
+        // define allowed parameters
+        final StringParameter helpParameter = parser.add(new StringParameter("Show help screen")
+                .addAliases("--help", "-h").setMandatory());
+
+        final StringParameter compileParameter = parser.add(new StringParameter("Compile code"))
+                .addAliases("--compile", "-c");
+
+        FileParameter fileParameter = parser.add(new FileParameter("Input file")
+                .addAliases("-i").mustExist());
+
+        createTemporaryFile();
+
+        // check help generation
+        parser.showHelp();
+
+        // parse arguments
+        parser.parse(new String[]{"--help", "section", "-i", "/tmp/file with spaces"});
+
+        // --help was in the arguments
+        assertTrue(helpParameter.isSpecified());
+
+        // compile was not present
+        assertFalse(compileParameter.isSpecified());
+
+        // validate that help argument was "section"
+        assertEquals("section", helpParameter.getValue());
+
+        assertTrue(fileParameter.isSpecified());
+        assertEquals("/tmp/file with spaces", fileParameter.getValue().getAbsolutePath());
+
+    }
+
+    private void createTemporaryFile() throws IOException {
+        File fileWithSpaces = new File("/tmp/file with spaces");
+        FileWriter writer = new FileWriter(fileWithSpaces);
+        writer.write("test");
+        writer.close();
+    }
+}
diff --git a/tools/commit and push b/tools/commit and push
new file mode 100755 (executable)
index 0000000..057b511
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+cd "${0%/*}"; if [ "$1" != "T" ]; then gnome-terminal -e "'$0' T"; exit; fi;
+
+cd ..
+
+cola
+git push
+
+echo ""
+echo "Press ENTER to close this window."
+read
diff --git a/tools/open with IntelliJ IDEA b/tools/open with IntelliJ IDEA
new file mode 100755 (executable)
index 0000000..de9bae5
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+#
+# This is a helper bash script that starts IntelliJ with the current project.
+# Script is written is such a way that you can simply click on it in file
+# navigator to run it.
+#
+#
+# Script assumes:
+#
+#    + GNU operating system
+#    + IntelliJ is installed and commandline launcher "idea" is enabled.
+#
+
+cd "${0%/*}"
+cd ..
+
+setsid idea . &>/dev/null
diff --git a/tools/update web site b/tools/update web site
new file mode 100755 (executable)
index 0000000..aebafec
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+if [ "$1" != "T" ]; then gnome-terminal -e "'$0' T"; exit; fi
+
+cd "${0%/*}"
+cd ..
+
+mvn clean package
+
+rm -rf doc/apidocs/
+cp -r target/apidocs/ doc/
+
+rsync -avz --delete  -e 'ssh -p 10006' doc/ n0@www3.svjatoslav.eu:/mnt/big/projects/cli-helper/
+
+echo
+echo "Press ENTER to close this terminal"
+read