0

I'm trying to build a Haskell CLI that can either read in strings from stdin or from arguments like so:

cat colors-multi-line | colorshift -d 10

colorshift -d 10 "#FFFFFF"

How would I accomplish this?

4
  • You do what you just said. You either read something from the command line using getArgs or you read something from stdin using getLine. You've not said when you want it to be one or the other - but basically, just apply whatever criteria you have for this. Commented Jul 7, 2018 at 23:27
  • If the user doesn't provide anything to stdin when the program starts, I'd like it to expect an argument with their input. If no input is found from either, the help screen should display. Commented Jul 7, 2018 at 23:29
  • You can import getArgs System.Environment, and do pattern matching on the result of getArgs. ``` import System.Environment main = do args <- getArgs case args of [flag, n] -> _ [flag, n, color] -> _ -> _ ``` Commented Jul 8, 2018 at 3:18
  • @CarolynSaunders You can't check if anything is on STDIN - it could come with any amount of delay. Imagine incredibly_long_running_application | your_program Commented Jul 8, 2018 at 8:03

1 Answer 1

1

There are several libraries to handle CLI argument parsing. optparse-applicative is the one with which I'm most familiar. getLine and getContents in Preluderead from STDIN.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.