File: FakeChanges.hs

package info (click to toggle)
haskell-debian 4.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 480 kB
  • sloc: haskell: 3,874; makefile: 5
file content (38 lines) | stat: -rw-r--r-- 1,075 bytes parent folder | download | duplicates (4)
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.Directory (canonicalizePath)
import System.FilePath

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] -> canonicalizePath dir
             _ -> return "."
       writeFile (outdir </> changesFP) $! contents