<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions and answers in tools.cli</title>
<link>https://ask.clojure.org/index.php/qa/contrib-libs/tools-cli</link>
<description></description>
<item>
<title>Answered: tools.cli: capture unrecognized options as unparsed arguments</title>
<link>https://ask.clojure.org/index.php/14977/tools-cli-capture-unrecognized-options-unparsed-arguments?show=14985#a14985</link>
<description>&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/TCLI-107&quot;&gt;https://clojure.atlassian.net/browse/TCLI-107&lt;/a&gt; with a proposed syntax:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;:subcommand :explicit&lt;/code&gt; will have the same meaning as &lt;code&gt;:in-order true&lt;/code&gt; does today&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:subcommand :implicit&lt;/code&gt; will have the behavior the OP wants here, i.e., an unknown option is treated as if there were an implicit subcommand present&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Deprecate &lt;code&gt;:in-order true&lt;/code&gt; (in favor of &lt;code&gt;:subcommand :explicit&lt;/code&gt;).&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14977/tools-cli-capture-unrecognized-options-unparsed-arguments?show=14985#a14985</guid>
<pubDate>Fri, 06 Mar 2026 01:40:33 +0000</pubDate>
</item>
<item>
<title>Answered: Dependency between options in Clojure/tools.cli ?</title>
<link>https://ask.clojure.org/index.php/14556/dependency-between-options-in-clojure-tools-cli?show=14558#a14558</link>
<description>&lt;p&gt;There's nothing built-in. The simplest solution would probably be to post-process the result of calling &lt;code&gt;parse-opts&lt;/code&gt; to check that if &lt;code&gt;:a&lt;/code&gt; is present, so are both &lt;code&gt;:f&lt;/code&gt; and &lt;code&gt;:d&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I often wrap &lt;code&gt;parse-opts&lt;/code&gt; in a post-processing step for &quot;global validation&quot; (that takes the result of &lt;code&gt;parse-opts&lt;/code&gt; and produces an identical structure, with extra &lt;code&gt;:errors&lt;/code&gt; entries).&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14556/dependency-between-options-in-clojure-tools-cli?show=14558#a14558</guid>
<pubDate>Tue, 27 May 2025 15:28:13 +0000</pubDate>
</item>
<item>
<title>Answered: tools.cli: Support default value for arg with value</title>
<link>https://ask.clojure.org/index.php/14524/tools-cli-support-default-value-for-arg-with-value?show=14525#a14525</link>
<description>&lt;p&gt;The closest you can get is this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;clojure.tools.cli=&amp;gt; (parse-opts [&quot;--diff=&quot;] [[nil &quot;--diff NAME&quot; &quot;Diff&quot; :parse-fn #(or (not-empty %) &quot;foo&quot;)]])
{:options {:diff &quot;foo&quot;}, :arguments [], :summary &quot;      --diff NAME  Diff&quot;, :errors nil}
clojure.tools.cli=&amp;gt; (parse-opts [&quot;--diff=bar&quot;] [[nil &quot;--diff NAME&quot; &quot;Diff&quot; :parse-fn #(or (not-empty %) &quot;foo&quot;)]])
{:options {:diff &quot;bar&quot;}, :arguments [], :summary &quot;      --diff NAME  Diff&quot;, :errors nil}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;clojure.tools.cli=&amp;gt; &lt;/p&gt;
&lt;p&gt;As discussed on Slack, there are reasonable cases for a value-bearing option to want to accept a string that starts with &lt;code&gt;--&lt;/code&gt; or just &lt;code&gt;-&lt;/code&gt; (consider &lt;code&gt;=&lt;/code&gt; to be optional here):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;meta-command --option-to-use=--cabbage... \
--divider=--sep-- \
--value=-1
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14524/tools-cli-support-default-value-for-arg-with-value?show=14525#a14525</guid>
<pubDate>Mon, 28 Apr 2025 19:08:37 +0000</pubDate>
</item>
<item>
<title>Answered: Incorrect docstring for parse-opts</title>
<link>https://ask.clojure.org/index.php/14275/incorrect-docstring-for-parse-opts?show=14276#a14276</link>
<description>&lt;p&gt;This relates to &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/14260/providing-nil-for-long-option-tools-cli-does-seem-work-readme&quot;&gt;https://ask.clojure.org/index.php/14260/providing-nil-for-long-option-tools-cli-does-seem-work-readme&lt;/a&gt; and I plan to update the docstrings and readme to fix both.&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14275/incorrect-docstring-for-parse-opts?show=14276#a14276</guid>
<pubDate>Tue, 03 Dec 2024 20:13:25 +0000</pubDate>
</item>
<item>
<title>Answered: Providing nil for long option in tools.cli does not seem to work per readme</title>
<link>https://ask.clojure.org/index.php/14260/providing-nil-for-long-option-tools-cli-does-seem-work-readme?show=14262#a14262</link>
<description>&lt;p&gt;Try adding &lt;code&gt;:required &quot;MODE&quot;&lt;/code&gt; after &lt;code&gt;:id :mode&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When there's no long option in the form of &lt;code&gt;--option ARG&lt;/code&gt;, the parameter is treated as a boolean flag, so you have to explicitly tell &lt;code&gt;tools.cli&lt;/code&gt; that an argument is required by the parameter.&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14260/providing-nil-for-long-option-tools-cli-does-seem-work-readme?show=14262#a14262</guid>
<pubDate>Tue, 19 Nov 2024 22:32:20 +0000</pubDate>
</item>
<item>
<title>Answered: Can't know if value in option map is default or user-supplied</title>
<link>https://ask.clojure.org/index.php/13555/cant-know-if-value-in-option-map-is-default-or-user-supplied?show=13558#a13558</link>
<description>&lt;p&gt;I'm not quite sure I understand what you're trying to do but I'm thinking the &lt;code&gt;:default-fn&lt;/code&gt; option may serve you better?&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13555/cant-know-if-value-in-option-map-is-default-or-user-supplied?show=13558#a13558</guid>
<pubDate>Fri, 15 Dec 2023 05:48:30 +0000</pubDate>
</item>
<item>
<title>Answered: Compile parser ahead of time</title>
<link>https://ask.clojure.org/index.php/12697/compile-parser-ahead-of-time?show=12703#a12703</link>
<description>&lt;p&gt;Created jira as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/TCLI-101&quot;&gt;https://clojure.atlassian.net/browse/TCLI-101&lt;/a&gt;&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12697/compile-parser-ahead-of-time?show=12703#a12703</guid>
<pubDate>Wed, 01 Mar 2023 15:54:31 +0000</pubDate>
</item>
<item>
<title>Answered: tools.cli: display default value for --[no-]foo flags in help summary</title>
<link>https://ask.clojure.org/index.php/12069/tools-cli-display-default-value-for-no-foo-flags-help-summary?show=12072#a12072</link>
<description>&lt;p&gt;Jira ticket created &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/TCLI-100&quot;&gt;https://clojure.atlassian.net/browse/TCLI-100&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I'll take a look at the implications of this and see if there are reasons not to display defaults.&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12069/tools-cli-display-default-value-for-no-foo-flags-help-summary?show=12072#a12072</guid>
<pubDate>Mon, 25 Jul 2022 20:07:05 +0000</pubDate>
</item>
<item>
<title>Answered: Tools.cli :validate: provide a way to post-validate (after updates)</title>
<link>https://ask.clojure.org/index.php/10267/tools-cli-validate-provide-way-post-validate-after-updates?show=10268#a10268</link>
<description>&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/TCLI-98&quot;&gt;https://clojure.atlassian.net/browse/TCLI-98&lt;/a&gt; -- released in 1.0.206&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10267/tools-cli-validate-provide-way-post-validate-after-updates?show=10268#a10268</guid>
<pubDate>Sat, 27 Feb 2021 21:09:55 +0000</pubDate>
</item>
<item>
<title>Answered: Tools.cli :validate: provide function of invalid value in addition to fixed string</title>
<link>https://ask.clojure.org/index.php/10265/tools-validate-provide-function-invalid-value-addition-string?show=10266#a10266</link>
<description>&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/TCLI-97&quot;&gt;https://clojure.atlassian.net/browse/TCLI-97&lt;/a&gt; - released in 1.0.206&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10265/tools-validate-provide-function-invalid-value-addition-string?show=10266#a10266</guid>
<pubDate>Sat, 27 Feb 2021 21:04:32 +0000</pubDate>
</item>
<item>
<title>Answered: Is it possible to parse positional arguments in tools.cli?</title>
<link>https://ask.clojure.org/index.php/9217/is-it-possible-to-parse-positional-arguments-in-tools-cli?show=9220#a9220</link>
<description>&lt;p&gt;As the maintainer of tools.cli, I'm going to give this some thought and decide whether to create a JIRA issue for it.&lt;/p&gt;
&lt;p&gt;Most programs that use tools.cli end up needing some boilerplate code for help/usage, as well as some additional parsing and/or validation of arguments so enhancing the library to make this easier would help &quot;everyone&quot; if it can be done in a fairly simple way.&lt;/p&gt;
&lt;p&gt;One conceptual issue to figure out is that the format for specifying options is only for actual options (i.e., starting with &lt;code&gt;-&lt;/code&gt; or &lt;code&gt;--&lt;/code&gt;) so there's currently nowhere to &quot;hang&quot; any free text argument processing right now.&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9217/is-it-possible-to-parse-positional-arguments-in-tools-cli?show=9220#a9220</guid>
<pubDate>Tue, 07 Apr 2020 17:23:10 +0000</pubDate>
</item>
<item>
<title>Answered: Review cli-matic for inspiration for enhancing tools.cli</title>
<link>https://ask.clojure.org/index.php/7812/review-cli-matic-for-inspiration-for-enhancing-tools-cli?show=7813#a7813</link>
<description>&lt;p&gt;Reference: &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/TCLI-92&quot;&gt;https://clojure.atlassian.net/browse/TCLI-92&lt;/a&gt; (reported by seancorfield) - closed, no action required (README updated)&lt;/p&gt;
</description>
<category>tools.cli</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/7812/review-cli-matic-for-inspiration-for-enhancing-tools-cli?show=7813#a7813</guid>
<pubDate>Wed, 26 Jun 2019 12:00:00 +0000</pubDate>
</item>
</channel>
</rss>