0
現在、コマンドライン引数の解析が必要なプロジェクトで作業しています。これまで私はthis tutorialに従ってきましたが、これは非常に有益でしたが、引数に変数(--author = example)を返す方法がわかりません。 parse [] = getContents
が原因でエラーが発生した(私はそれをコメント解除しなければならなかった)理由もわかりません。コメントoptparse-applicativeは、CLIと引数は、解析するための偉大なパッケージですThomasM.DuBuissonHaskellでのコマンドライン引数の解析
module Main where
import qualified System.Environment as SE
import qualified System.Exit as E
import qualified Lib as Lib
main = do
args <- SE.getArgs
rem <- parse args
Lib.someFunc
putStrLn rem
putStrLn "Hello"
tac = unlines . reverse . lines
parse ["--help"] = usage >> exit
parse ["--version"] = version >> exit
parse ["--author=xyz"] = return "xyz"
-- parse ["--author=?"] = ?
{-
this is the code I am trying to figure out... how do I get parse the passed in variable name?
-}
-- parse [] = getContents
{-
the above line generates this error when I run 'main' in GHCi:
*Main> <stdin>: hIsEOF: illegal operation (handle is semi-closed)
Process intero exited abnormally with code 1
-}
parse fs = concat `fmap` mapM readFile fs
usage = putStrLn "Usage: gc2"
version = putStrLn "gc2 -- git-cal in Haskell2010 - 0.1"
exit = E.exitWith E.ExitSuccess
die = E.exitWith (E.ExitFailure 1)
'getContents'は、すべての入力を取得し、する必要がありますが、ここで
optparse-applicative
を始めることができますだけのではあなたの例の実装でありますそれ以降の入力からは何も読まない。あなたはその契約を満足していますか?例えば 'Lib.someFunc'をチェックしてください。 – chi
ありがとう、それは意味があります(そして、私がSystem.ProcessをLib.someFuncで使用していたためにエラーが発生したようです)。 – kuwze
そこには引数解析ライブラリがあります。そのうちの1つを使用しない理由はありますか? –