Last active
August 3, 2022 10:16
-
-
Save borkdude/29926d5ece9f79b04629a822fdc4e011 to your computer and use it in GitHub Desktop.
babashka.cli args->opts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns cli-app | |
(:require [babashka.cli :as cli])) | |
(def spec {:hello {:desc "something"} | |
:foo {:desc "foo"} | |
:bar {:desc "bar" | |
:coerce []}}) | |
(def cli-opts {:spec spec | |
:args->opts (cons :foo (repeat :bar))}) | |
(defn foo | |
{:org.babashka/cli cli-opts} | |
[m] | |
(if (:help m) | |
(do | |
(println "Usage: foo [OPTIONS] FOO BAR+") | |
(println) | |
(println "Options:") | |
(println (cli/format-opts {:spec spec})) | |
(println)) | |
m)) | |
(foo (cli/parse-opts *command-line-args* cli-opts)) | |
;; $ bb /tmp/cli_app.clj --hello there arg1 arg2 arg3 | |
;; {:hello "there", :foo "arg1", :bar ["arg2" "arg3"]} | |
;; $ bb /tmp/cli_app.clj --help | |
;; Usage: foo [OPTIONS] FOO BAR+ | |
;; Options: | |
;; --hello something | |
;; --foo foo | |
;; --bar bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment