Clojure JIRAhttp://dev.clojure.org/jira/secure/IssueNavigator.jspa?reset=true&jqlQuery=project+%3D+TCLI+AND+resolution+%3D+Unresolved+AND+component+is+EMPTY+ORDER+BY+priority+DESC
An XML representation of a search requesten-us4.464925-07-2011RE: [TCLI-10] potential incorrect parsing
http://dev.clojure.org/jira/browse/TCLI-10?focusedCommentId=35332#comment-35332
Sun, 10 Aug 2014 15:01:16 -0500John Walker
<p>I am not able to reproduce this behavior. Would you create a gist or use code tags?</p>
<br/>
<br/>
<table>
<tr>
<td>Author:</td>
<td><a
href="http://dev.clojure.org/jira/secure/ViewProfile.jspa?name=johnwalker">John Walker</a>
(<a href="http://dev.clojure.org/jira/browse/TCLI-10">TCLI-10</a>)</td>
</tr>
</table>
http://dev.clojure.org/jira/browse/TCLI-10?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=35332\#worklog-35332RE: [TCLI-9] Support multiple validations
http://dev.clojure.org/jira/browse/TCLI-9?focusedCommentId=34447#comment-34447
Tue, 22 Apr 2014 00:21:16 -0500Sung Pae
<p>Hello Jean,</p>
<p>I've implemented your first suggestion (support multiple validations) and pushed it to master. I think it's a nice compromise.</p>
<p>From the patch header:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>This is an implemenation (sic) of the first suggestion, multiple validation
functions.
The :validation entry can now have multiple entries, which are
partitioned into pairs, then split into the vector entries
:validation-fn and :validation-msg. It would be nice to have
a pluralized key name here, but we decline this for backwards
compatibility.
Non-collection values of :validate-fn and :validate-msg continue to be
supported by conditional wrapping.
Example:
[["-f" "--file PATH"
:parse-fn io/file
:validate [#(.exists %) "File does not exist"
#(.isFile %) "Path is not a regular file"
#(.canRead %) "File is unreadable"]]]
Addresses TCLI-9.
</pre>
</div></div>
<p><a href="https://github.com/clojure/tools.cli/commit/56ecd5f305d444bbf6dcd28f4f4adce58ebc0de4">https://github.com/clojure/tools.cli/commit/56ecd5f305d444bbf6dcd28f4f4adce58ebc0de4</a></p>
<br/>
<br/>
<table>
<tr>
<td>Author:</td>
<td><a
href="http://dev.clojure.org/jira/secure/ViewProfile.jspa?name=guns">Sung Pae</a>
(<a href="http://dev.clojure.org/jira/browse/TCLI-9">TCLI-9</a>)</td>
</tr>
</table>
http://dev.clojure.org/jira/browse/TCLI-9?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34447\#worklog-34447RE: [TCLI-9] Support multiple validations
http://dev.clojure.org/jira/browse/TCLI-9?focusedCommentId=33839#comment-33839
Mon, 17 Feb 2014 23:19:35 -0600Sung Pae
<p>Saying yes to this kind of enhancement should be quite easy, but I only have a single reservation: adding a second type of validation function that is a logical inverse of the existing type seems confusing.</p>
<p>What do you think about using exceptions to carry error messages?</p>
<p><a href="https://gist.github.com/guns/9065033">https://gist.github.com/guns/9065033</a><br/>
(gaah I don't know how to use JIRA at all)</p>
<p>The existing implementation already catches Exceptions, throws away the error message, and returns nil. This is more verbose than <tt>fn -&gt; optarg -&gt; nil | String</tt>, but it is aligned to the current logical convention.</p>
<br/>
<br/>
<table>
<tr>
<td>Author:</td>
<td><a
href="http://dev.clojure.org/jira/secure/ViewProfile.jspa?name=guns">Sung Pae</a>
(<a href="http://dev.clojure.org/jira/browse/TCLI-9">TCLI-9</a>)</td>
</tr>
<tr>
<td>Edited by:</td>
<td><a href="http://dev.clojure.org/jira/secure/ViewProfile.jspa?name=guns">Sung Pae</a></td>
</tr>
</table>
http://dev.clojure.org/jira/browse/TCLI-9?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33839\#worklog-33839RE: [TCLI-9] Support multiple validations
http://dev.clojure.org/jira/browse/TCLI-9?focusedCommentId=33762#comment-33762
Fri, 14 Feb 2014 09:44:25 -0600Jean Niklas L'orange
<p>Hello Sung,</p>
<p>No worries about the response time.</p>
<p>It's not necessarily the fact that it is more verbose, just that I would like to give good, descriptive error messages back. While it's easy for each of the different errors, I think it's better to say exactly what the problem is. For instance, if I want to take in an input directory path, I want to ensure that is is a legal path, and if the file already exists, it must be a directory:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>["-i" "--input-directory DIR"
:validate
#(if-not (ok-path? %)
(format "Input directory path '%s' is malformed" %)
(let [f (File. %)]
(if (and (.exists f) (not (.isDirectory f)))
(format "Input directory '%s' is a file, not a directory" %))))]
</pre>
</div></div>
<p>However, I can understand that such functionality can be a bit over the top for a CLI library. As long as you've compared/considered the different possibilities, I am content with whatever choice you take.</p>
<br/>
<br/>
<table>
<tr>
<td>Author:</td>
<td><a
href="http://dev.clojure.org/jira/secure/ViewProfile.jspa?name=hypirion">Jean Niklas L&#39;orange</a>
(<a href="http://dev.clojure.org/jira/browse/TCLI-9">TCLI-9</a>)</td>
</tr>
<tr>
<td>Edited by:</td>
<td><a href="http://dev.clojure.org/jira/secure/ViewProfile.jspa?name=hypirion">Jean Niklas L&#39;orange</a></td>
</tr>
</table>
http://dev.clojure.org/jira/browse/TCLI-9?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33762\#worklog-33762RE: [TCLI-9] Support multiple validations
http://dev.clojure.org/jira/browse/TCLI-9?focusedCommentId=33748#comment-33748
Thu, 13 Feb 2014 22:35:36 -0600Sung Pae
<p>My apologies for this delayed response. I thought that I would be emailed on creation of new issues, but this does not appear to be the case. This is the second time this has happened, so I will clearly have to rig something up to keep on top of this board.</p>
<p>&gt; In many cases, I have input arguments where I want to perform multiple validations, and return different error messages based upon that. Would it be reasonable to have multiple validation functions, or being able to have a validation function returning nil if no errors exists, and an error string if not?</p>
<p>&gt; If this seems like an interesting idea, I believe that the easiest and simplest solution would be to support a single validation function returning the actual error message. The reationale for this is that multiple validations may require a complex rule system (ordering? should it short-circuit, or should it return multiple error messages?), and as such, it's better to have those rules evident in the validation function.</p>
<p>The single largest reason I opted against implementing validations like this was that I dislike the corresponding linguistic and syntactic awkwardness of inverting the logic:</p>
<p> :validate <span class="error">&#91;pred &quot;Must satisfy pred&quot;&#93;</span> ;; Error message is optional</p>
<p>vs</p>
<p> :validate #(when-not (pred %) "Must satisfy pred")</p>
<p>The first approach looks like a standard assertion, while the second requires an explicit branch and must return a truthy value to register a failure.¹</p>
<p>Now, the second example is more powerful for the reasons you outline, but since the vast majority of command line option arguments are semantically simple values such as numbers, filenames, and hostnames, I chose to optimize for the common case in order to have the terser syntax.</p>
<p>That said, I am happy to be convinced otherwise. Could you please provide an example of an option specification where returning different error messages for different failures is significantly better than something like the following?</p>
<p>["<del>o" "</del>-option EXAMPLE"<br/>
:validate [#(and (foo? %) (bar? %) (baz? %))<br/>
"Must be a foo that is also a bar and a baz"]]</p>
<p>I am currently of the mind that a per-option error summary is sufficient for an advanced user interface like the command line, and becomes complete with a link to a documentation URL (or man page).</p>
<p>Thank you.</p>
<p>¹ I usually name functions of the second type `validation-errors` instead of `validate` because I find this confusing:</p>
<p> (when-not (validate input) "This seems awkward.")</p>
<br/>
<br/>
<table>
<tr>
<td>Author:</td>
<td><a
href="http://dev.clojure.org/jira/secure/ViewProfile.jspa?name=guns">Sung Pae</a>
(<a href="http://dev.clojure.org/jira/browse/TCLI-9">TCLI-9</a>)</td>
</tr>
</table>
http://dev.clojure.org/jira/browse/TCLI-9?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33748\#worklog-33748