哈斯克尔。解析命令行参数
我正在学习Haskell编程语言。现在我正在学习IO。我想编写简单的命令行util。 util获取两个文件(JSON或YAML),对它们进行比较并输出比较结果(JSON,YAML,纯文本)。
我认为,我的uter界面是:
my_util "path to first file" "path to second file" -- format JSON.
我决定使用cmdargs。但是现在,我的界面显示了:
my_util -f="path to first file" -s="path to second file" -- format JSON.
我做了什么。
data Gendiff = Gendiff
{first_file :: String
,second_file :: String
,format :: String
}
deriving (Data,Typeable,Show,Eq)
gendiff = Gendiff
{first_file = def &= name "f" &= typDir &= help "path to first file to compare" &= typ "String"
,second_file = def &= name "s" &= typDir &= help "path to second file to compare" &= typ "String"
,format = &= opt "JSON" &= help "set format of output" &= typ "String"
} &=
verbosity &=
help "Compares two configuration files and shows a difference." &=
summary " Gendiff v0.0.1, (C) dosart"
main = print =<< cmdArgs gendif
我如何制作第一个变体?如何设置格式标志默认值?
I am learning Haskell programming language. Now I am studying IO. I'd like to write simple command line util. The util take two files (JSON or YAML), compare them and output the result of compare (JSON, YAML, Plain text).
I think, the interface of my util would be that:
my_util "path to first file" "path to second file" -- format JSON.
I decided to use CmdArgs. But now, my interface show so:
my_util -f="path to first file" -s="path to second file" -- format JSON.
What I was done.
data Gendiff = Gendiff
{first_file :: String
,second_file :: String
,format :: String
}
deriving (Data,Typeable,Show,Eq)
gendiff = Gendiff
{first_file = def &= name "f" &= typDir &= help "path to first file to compare" &= typ "String"
,second_file = def &= name "s" &= typDir &= help "path to second file to compare" &= typ "String"
,format = &= opt "JSON" &= help "set format of output" &= typ "String"
} &=
verbosity &=
help "Compares two configuration files and shows a difference." &=
summary " Gendiff v0.0.1, (C) dosart"
main = print =<< cmdArgs gendif
How I can make first variant? How to set the format flag default value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您会使用
args
。这样的事情:I guess you would use
args
. Something like this: