optparse-generic 项目教程

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

  • 25
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江燕娇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值