Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass command-line args to -main #6

Merged
merged 4 commits into from
Aug 24, 2021
Merged

Pass command-line args to -main #6

merged 4 commits into from
Aug 24, 2021

Conversation

athos
Copy link
Owner

@athos athos commented Aug 24, 2021

Currently, there is no way to pass command-line args to the -main function when -m is specified.
This PR provides the way to do that:

$ cat src/arith.clj
(ns arith)

(defn -main [op & args]
  (if-let [op' (case op "add" + "sub" - nil)]
    (let [args' (map read-string args)]
      (prn (apply op' args')))
    (throw (ex-info (str "Unknown op: " op) {}))))
$ trench -m arith add 1 2
3
$ trench -m arith sub 3 1
2
$

Also, -- can be used as a separator to distinguish arguments to pass to -main from the ones that should be passed directly to Trenchman:

$ trench -m arith -- add 1 2

@athos athos merged commit 53bc550 into main Aug 24, 2021
@athos athos deleted the feature/main-args branch August 24, 2021 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant