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?
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.
getArgsor you read something from stdin usinggetLine. You've not said when you want it to be one or the other - but basically, just apply whatever criteria you have for this.getArgsSystem.Environment, and do pattern matching on the result ofgetArgs. ``` import System.Environment main = do args <- getArgs case args of [flag, n] -> _ [flag, n, color] -> _ -> _ ```incredibly_long_running_application | your_program