Haskell 带有cmdargs的有序参数

Haskell 带有cmdargs的有序参数,haskell,haskell-cmdargs,Haskell,Haskell Cmdargs,我想创建一个程序谁得到一些参数与。 我想检索文件路径列表和要执行的操作列表。我需要执行这些文件,并按顺序执行这些操作 我的论点声明如下: data Options = Mode1 { input :: [FilePath] , act1 :: Bool , act2 :: Bool , act3 :: Bool } deriving (Data, Typea

我想创建一个程序谁得到一些参数与。 我想检索文件路径列表和要执行的操作列表。我需要执行这些文件,并按顺序执行这些操作

我的论点声明如下:

data Options = 
    Mode1   { 
              input :: [FilePath]
            , act1 :: Bool
            , act2 :: Bool
            , act3 :: Bool
            } deriving (Data, Typeable, Show, Eq)

mode1 = 
  Mode1 { 
            input   = []      &= name "i" &= help "input file"   &= typ "FILE"
          , act1    = False   &= name "a" &= help "action 1"     &= typ "ACTION"
          , act2    = False   &= name "b" &= help "action 2"     &= typ "ACTION"
          , act3    = False   &= name "c" &= help "action 3"     &= typ "ACTION"
        }
./myprog --act1 --act2 --act3 --input="file1.txt" --input="file2.txt"
./myprog --act3 --act1        --input="file1.txt" --input="file2.txt"
./myprog --act2 --act3 --act1 --input="file1.txt" --input="file2.txt"
我设法按照
String
filepath
)列表的顺序获得了filepath列表。通过这种方式,我可以通过以下方式获得输入文件:

./myprog --input="file1.txt" --input="file2.txt"
./myprog --input="file2.txt" --input="file1.txt"
但是我不能让我的操作被排序,因为它们被声明为
Bool
。 我想把我的论点如下:

data Options = 
    Mode1   { 
              input :: [FilePath]
            , act1 :: Bool
            , act2 :: Bool
            , act3 :: Bool
            } deriving (Data, Typeable, Show, Eq)

mode1 = 
  Mode1 { 
            input   = []      &= name "i" &= help "input file"   &= typ "FILE"
          , act1    = False   &= name "a" &= help "action 1"     &= typ "ACTION"
          , act2    = False   &= name "b" &= help "action 2"     &= typ "ACTION"
          , act3    = False   &= name "c" &= help "action 3"     &= typ "ACTION"
        }
./myprog --act1 --act2 --act3 --input="file1.txt" --input="file2.txt"
./myprog --act3 --act1        --input="file1.txt" --input="file2.txt"
./myprog --act2 --act3 --act1 --input="file1.txt" --input="file2.txt"
以获得不同的输出结果

使用cmdargs是否可以按顺序检索不同的参数?

使用cmdargs是否可以按顺序检索不同的参数

是的,有

使用:

{-# LANGUAGE DeriveDataTypeable #-}
import System.Console.CmdArgs

data Act = 
    ActA
  | ActB
  | ActC
  deriving (Show, Typeable,  Data, Eq)

data Options = Mode1
  { input :: [FilePath]
  , acts :: [Act]
  } deriving (Show, Data, Typeable, Eq)

actsDef :: [Act]
actsDef = (enum
  [ [] &= ignore
  , [ActA] &= name "a" &= help "action a"
  , [ActB] &= name "b" &= help "action b" 
  , [ActC] &= name "c" &= help "action c" 
  ]) &= typ "ACTION"

mode :: Options
mode = Mode1
  { input = [] &= name "1" &= help "input file" &= typ "FILE"
  , acts = actsDef 
  }

main = print =<< cmdArgs mode
{-#语言派生数据类型化}
导入System.Console.CmdArgs
数据法案=
行动
|ActB
|ActC
派生(显示、可打印、数据、等式)
数据选项=模式1
{输入::[FilePath]
,法案::[法案]
}派生(显示、数据、可键入、等式)
actsDef::[法案]
actsDef=(枚举)
[[]&=忽略
,[ActA]&=名称“a”&=帮助“行动a”
,[ActB]&=名称“b”&=帮助“操作b”
,[ActC]&=名称“c”&=帮助“操作c”
])&=典型的“动作”
模式::选项
模式=模式1
{input=[]&=name“1”&=help“输入文件”&=typ“文件”
,acts=actsDef
}

main=print=看起来这些已在最近几个版本中删除