Comments (4)
I added this to test/cli_matic/presets_test.cljc
(comment
(test-string)
(use 'clojure.tools.trace)
(trace-ns cli-matic.core)
(trace-ns cli-matic.utils)
(trace-ns cli-matic.utils-v2)
(untrace-ns clojure.tools.cli)
(parse-cmds-simpler
["foo"]
(mkDummyCfg {:option "val" :as "x" :type :string :multiple true
:default ["a" "b" "c"]}))
(parse-cmds-simpler
["foo" "--val" "x" "--val" "y"]
(mkDummyCfg {:option "val" :as "x" :type :string :multiple true
:default ["a" "b" "c"]}))
)
And it seems the issue might be related to mk-cli-option
in src/cli_matic/utils.cljc
.
TRACE t10880: | | (cli-matic.core/parse-cmds-with-defaults [{:option "val", :as "x", :type :string, :multiple true, :default ["a" "b" "c"]}] [] false #function[cli-matic.platform/read-env])
TRACE t10881: | | | (cli-matic.utils/cm-opts->cli-opts [{:option "val", :as "x", :type :string, :multiple true, :default ["a" "b" "c"]}])
TRACE t10882: | | | | (cli-matic.utils/mk-cli-option {:option "val", :as "x", :type :string, :multiple true, :default ["a" "b" "c"]})
TRACE t10883: | | | | | (cli-matic.utils/asString "x")
TRACE t10883: | | | | | => "x"
TRACE t10884: | | | | | (cli-matic.utils/get-cli-option :string)
TRACE t10884: | | | | | => {:placeholder "S"}
TRACE t10885: | | | | | (cli-matic.utils/mk-short-opt nil)
TRACE t10885: | | | | | => nil
TRACE t10886: | | | | | (cli-matic.utils/mk-long-opt "val" "S" :string)
TRACE t10886: | | | | | => "--val S"
TRACE t10887: | | | | | (cli-matic.utils/mk-env-name "x" nil false)
TRACE t10887: | | | | | => "x"
TRACE t10882: | | | | => [nil "--val S" "x" :default "a" "b" "c" :assoc-fn #function[clojure.tools.trace/trace-var*/fn--8942/tracing-wrapper--8943]]
TRACE t10881: | | | => [[nil "--val S" "x" :default "a" "b" "c" :assoc-fn #function[clojure.tools.trace/trace-var*/fn--8942/tracing-wrapper--8943]] ["-?" "--help" "" :id :_help_trigger]]
TRACE t10880: | | => {:options {:val "a"}, :arguments [], :summary " --val S a x\n -?, --help", :errors nil}
from cli-matic.
The issue is with the use of flatten
call in the case of multiple
.
(defn mk-cli-option
"Builds a tools.cli option out of our own format.
If for-parsing is true, the option will be used for parsing;
if false, for generating help messages.
"
[{:keys [option short as type default multiple env]}]
(let [as_description (asString as)
preset (get-cli-option type)
placeholder (str (:placeholder preset)
(if (= :present default) "*" ""))
positional-opts [(mk-short-opt short)
(mk-long-opt option placeholder type)
(mk-env-name as_description env false)]
;; step 1 - remove :placeholder
opts-1 (dissoc preset :placeholder)
;; step 2 - add default if present and is not ":present"
opts-2 (if (and (some? default)
(not= :present default))
(assoc opts-1 :default default)
opts-1)
;; step 3 - if multivalue, add correct assoc-fns
opts-3 (if multiple
(assoc opts-2 :assoc-fn assoc-new-multivalue)
opts-2)]
(println "p-opts" positional-opts)
(println "1" opts-1)
(println "2" opts-2)
(println "3" opts-3)
(apply
conj positional-opts
(flatten (seq opts-3)))))
(comment
(use 'clojure.tools.cli)
(let [opt
(mk-cli-option
{:option "val", :as "x", :type :string, :multiple true, :default ["a" "b" "c"]})]
(println "optsss" opt)
(parse-opts [] [opt]))
)
Results;
p-opts [nil --val S x]
1 {}
2 {:default [a b c]}
3 {:default [a b c], :assoc-fn #function[cli-matic.utils/assoc-new-multivalue]}
optsss [nil --val S x :default a b c :assoc-fn #function[cli-matic.utils/assoc-new-multivalue]]
{:options {:val "a"}, :arguments [], :summary " --val S a x", :errors nil}
; Warning: The following options to parse-opts are unrecognized: b
from cli-matic.
The issue is with flatten.
from cli-matic.
Seems like the issue is with tools-cli or my understanding of how to use it.
Copied the example from the repo and added a value to :default
for -f
.
(def cli-options
[
["-f" "--file NAME" "File names to read"
:multi true ; use :update-fn to combine multiple instance of -f/--file
:default ["test"]
;; with :multi true, the :update-fn is passed both the existing parsed
;; value(s) and the new parsed value from each option
:update-fn conj]
])
(parse-opts args cli-options)
Parsing cli args using the above structure yields both default and the user supplied options.
clj -M -m cli.example -f csv
{:options {:file [test csv]}, :arguments [], :summary
-f, --file NAME ["test"] File names to read
:errors nil}
from cli-matic.
Related Issues (20)
- example not executing as documented. HOT 1
- Do not dump stack trace on mistyped subcommand HOT 3
- [Ftr] dd sysexit codes
- Return value from `(doall ...)` causes `getReturnValue` to throw
- clj -m raises warning
- [Ftr] Flag to not run System/Exit HOT 5
- :default values for :jsonfile options do not parse files
- [Ftr] Babashka: avoid external bb.edn file HOT 2
- Glob multiple position arguments
- Update all dependencies but CLJ
- [Ftr] Snappier scripts with tiered compilation
- [Ftr] Support repetition for flags ? e.g. ansible style verbose: -v / -vv / -vvv HOT 1
- [Ftr] Generate a basic UI for calling the application based on cli-matic configuration HOT 1
- [Ftr] Ability to extend type presets, like `:file` for conforming the arg to `File`
- [Ftr] Ability to *disable* -? gloabl help HOT 1
- cli-matic can enable global spec instrumentation under inappropriate circumstances HOT 2
- Returning lazy sequences from :runs throws - IPending is not IDeref HOT 1
- Update tools.cli to 1.0.219 HOT 1
- Remove contributors from README HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cli-matic.