File: FakeChanges.hs

package info (click to toggle)
haskell-debian 3.64-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 364 kB
  • sloc: haskell: 3,226; ansic: 8; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 1,063 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Main where

import Debian.Util.FakeChanges
import System.Environment
import System.Console.GetOpt
import System.FilePath
import System.Unix.FilePath (realpath)

data Flag 
    = OutputDir FilePath
       deriving Show
    
options :: [OptDescr Flag]
options =
     [ Option ['o']     ["output"]  (ReqArg OutputDir "DIRECTORY")  "output DIRECTORY"
     ]


fakeChangesOpts :: [String] -> IO ([Flag], [FilePath])
fakeChangesOpts argv = 
    case getOpt Permute options argv of
      (o,files,[]) | not (null files) -> return (o, files)
      (_,_,errs) -> 
          do h <- header
             error $ (concat errs ++ usageInfo h options)
    where header =
              do pn <- getProgName
                 return $ "\nUsage: " ++ pn ++ " [OPTION...] files..."
main =
    do args <- getArgs
       (opts, files) <- fakeChangesOpts args
       (changesFP, contents) <- fakeChanges files
       outdir <-
           case opts of
             [OutputDir dir] -> realpath dir
             _ -> return "."
       writeFile (outdir </> changesFP) $! contents