-- Author: Andy Stewart -- Maintainer: Andy Stewart -- -- Copyright (C) 2010 Andy Stewart, all rights reserved. -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . module Main where import Distribution.PackageDescription.Parse import Distribution.PackageDescription import Distribution.Package import Distribution.Verbosity import Distribution.Version import System.Directory import System.FilePath import Data.List import System.Process -- | Main. main :: IO () main = do -- Get cabal file. currentDir <- getCurrentDirectory files <- getDirectoryContents currentDir let cabalFiles = filter (\x -> ".cabal" `isSuffixOf` x) files case cabalFiles of [] -> putStrLn "Haven't find .cabal file under current directory." _ -> do (GenericPackageDescription {packageDescription = PackageDescription {package = PackageIdentifier {pkgName = PackageName name ,pkgVersion = Version {versionBranch = version}}} }) <- readPackageDescription normal (head cabalFiles) let packagePath = currentDir "dist" (name ++ "-" ++ showVersion version ++ ".tar.gz") handle <- runCommand $ "cabal sdist && cabal upload " ++ packagePath waitForProcess handle return () -- | Convert version [x,y,z] to "x.y.z". showVersion :: [Int] -> String showVersion [] = "" showVersion [x] = show x showVersion (x:xs) = (show x ++ ".") ++ showVersion xs