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

Support for STDIN #28

Closed
gaberger opened this issue Jul 13, 2018 · 6 comments
Closed

Support for STDIN #28

gaberger opened this issue Jul 13, 2018 · 6 comments
Labels
question Further information is requested

Comments

@gaberger
Copy link

I hacked something together that looks like

 (let
   [bf (java.io.BufferedReader. *in*)]
    (if
     (.ready bf)
      (let
       [conf (slurp *in*) vargs (into [] args)]
        (run-cmd (conj vargs "--stdin" conf) STDIN_INPUT))
      (run-cmd args FILE_INPUT))))

where STDIN_INPUT

(def
  STDIN_INPUT
  {:app
   {:command "nparser",
    :description "A command-line configuration generator",
    :version "0.1.2"},
   :global-opts [],
   :commands
   [{:command "to-json",
     :description "Generate JSON from a config",
     :opts
     [{:option "stdin",
       :as "Config input file",
       :type :string,
       :default :present}
      {:option "grammar",
       :as "Grammar file",
       :type :string,
       :default :present}],
     :runs gen-json}
    {:command "to-config",
     :description "Generate config from an input file",
     :opts
     [{:option "stdin",
       :as "JSON input file",
       :type :string,
       :default :present}],
     :runs gen-config}]})

not very idiomatic, but would be great to incorporate this into cli-matic..

The primary use-case is now that we have GRAALVM we can native-compile CLJ code into binary artifacts to build command-line apps..

@l3nz
Copy link
Owner

l3nz commented Jul 14, 2018

Hi, thanks for your comment. I am not sure how that is supposed to work - like, how would you use it?
In general, if you have a type of :jsonfile, Cli-matic will read the file and convert it to a Clojue data structure.

As for stdin, you could use /dev/stdinbut if you have something that is easier to use I'd love to add it.

As a side note, Graal is definitely a game changer - though I personally have not had much success playing with it. But I only tried once on some VMs and noticed it was taking forever.

@l3nz
Copy link
Owner

l3nz commented Jul 14, 2018

BTW, as for GraalVM, have a look here: #29 💡

@l3nz
Copy link
Owner

l3nz commented Jul 20, 2018

@l3nz
Copy link
Owner

l3nz commented Aug 27, 2018

I am not sure about stdin, as stdin is a file, so you can use it as /dev/stdin as a normal file (and if you want, it could be the default for a parameter, so you do not actually specify it).

Maybe we could use "-", so that it gets expanded to /dev/stdin or whatever it is when on Windows?

@l3nz l3nz added the question Further information is requested label Nov 15, 2018
@TimoKramer
Copy link
Contributor

Hi there, do you think it is sufficient to add stdin support for :slurp? I need the feature for a project linked above.
What I added so far is that one can use - for placeholder when requiring stdin.

What do you think?

@l3nz
Copy link
Owner

l3nz commented May 29, 2022

Merged

@l3nz l3nz closed this as completed May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants