optparse-generic 项目教程

随笔20小时前发布 咸丰贝安堂
4 0 0

optparse-generic 项目教程

optparse-genericAuto-generate a command-line parser for your datatype项目地址:https://gitcode.com/gh_mirrors/op/optparse-generic

1. 项目的目录结构及介绍




optparse-generic/


├── src/


│   ├── Options/


│   │   ├── Generic.hs


│   │   └── ...


│   └── ...


├── example/


│   ├── Example.hs


│   └── ...


├── LICENSE


├── README.md


├── Setup.hs


├── optparse-generic.cabal


└── ...

src/: 包含项目的主要源代码文件。
Options/: 包含与命令行解析相关的模块。
Generic.hs: 核心模块,用于自动生成命令行解析器。 example/: 包含示例代码,展示如何使用项目。
Example.hs: 示例文件,演示如何定义和解析命令行参数。 LICENSE: 项目的许可证文件。README.md: 项目的介绍和使用说明。Setup.hs: 用于构建项目的脚本。optparse-generic.cabal: 项目的配置文件,包含构建信息和依赖项。

2. 项目的启动文件介绍

项目的启动文件通常是指示例代码文件 example/Example.hs。该文件展示了如何使用 optparse-generic 库来定义和解析命令行参数。




-- example/Example.hs


{-# LANGUAGE DeriveGeneric #-}


{-# LANGUAGE OverloadedStrings #-}


 


import Options.Generic


 


data Example = Example { foo :: Int, bar :: Double } deriving (Generic, Show)





instance ParseRecord Example





main = do


  x <- getRecord "Test program"


  print (x :: Example)



DeriveGeneric: 启用 DeriveGeneric 扩展,以便自动生成 Generic 实例。OverloadedStrings: 启用 OverloadedStrings 扩展,以便使用字符串字面量。Options.Generic: 导入 optparse-generic 库的核心模块。Example: 定义一个包含 foobar 字段的记录类型。ParseRecord: 为 Example 类型生成命令行解析器。main: 主函数,使用 getRecord 函数解析命令行参数并打印结果。

3. 项目的配置文件介绍

项目的配置文件是 optparse-generic.cabal。该文件包含了项目的构建信息、依赖项和其他配置。




name:                optparse-generic


version:             1.5.2


synopsis:            Auto-generate a command-line parser for your datatype


description:         This library auto-generates command-line parsers for data types using Haskell's built-in support for generic programming.


homepage:            https://github.com/Gabriella439/optparse-generic


license:             BSD3


author:              Gabriella Gonzalez


maintainer:          Gabriella@gmail.com


category:            System


build-type:          Simple


extra-source-files:  README.md


cabal-version:       >=1.10


 


library


  exposed-modules:     Options.Generic


  other-modules:       Paths_optparse_generic


  build-depends:       base >=4.8 && <5


                     , optparse-applicative >=0.13.0.0


                     , transformers >=0.5.2.0


  default-language:    Haskell2010


 


executable optparse-generic-example


  main-is:             Example.hs


  other-modules:       Paths_optparse_generic


  build-depends:       base >=4.8 && <5


                     , optparse-generic


  default-language:    Haskell2010

name: 项目名称。version: 项目版本。synopsis: 项目简要描述。description: 项目详细描述。homepage: 项目主页。license: 项目许可证。author: 项目作者。maintainer: 项目维护者。category: 项目分类。build-type: 构建类型。extra-source-files: 额外的源文件。cabal-version: 所需的 Cabal 版本。library: 库部分,定义了暴露的模块和依赖项。executable:

optparse-genericAuto-generate a command-line parser for your datatype项目地址:https://gitcode.com/gh_mirrors/op/optparse-generic

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...