summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2015-09-25 14:49:55 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2015-09-25 14:49:55 +0200
commitea7d97498275a23fbda06e168904ee261f29594e (patch)
treebe37b7cdd9a9312208039ae89c4d323013d41642
parentbbacb450761ef7017a4a86a104ca5464f7240343 (diff)
parent9c9fe95a3580307215d76f130102729c5bb521c9 (diff)
downloadhakyll-ea7d97498275a23fbda06e168904ee261f29594e.tar.gz
Merge pull request #374 from Javran/cmdline-args
prevent hakyll-init from generating directory with leading hyphen(s)
-rw-r--r--src/Hakyll/Init.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/Hakyll/Init.hs b/src/Hakyll/Init.hs
index 9d90f31..71055f0 100644
--- a/src/Hakyll/Init.hs
+++ b/src/Hakyll/Init.hs
@@ -9,7 +9,7 @@ import Control.Arrow (first)
import Control.Monad (forM_)
import Data.Char (isAlphaNum, isNumber)
import Data.List (foldl')
-import Data.List (intercalate)
+import Data.List (intercalate, isPrefixOf)
import Data.Version (Version (..))
import System.Directory (canonicalizePath, copyFile)
import System.Environment (getArgs, getProgName)
@@ -31,7 +31,13 @@ main = do
files <- getRecursiveContents (const $ return False) srcDir
case args of
- [dstDir] -> do
+ -- When the argument begins with hyphens, it's more likely that the user
+ -- intends to attempt some arguments like ("--help", "-h", "--version", etc.)
+ -- rather than create directory with that name.
+ -- If dstDir begins with hyphens, the guard will prevent it from creating
+ -- directory with that name so we can fall to the second alternative
+ -- which prints a usage info for user.
+ [dstDir] | not ("-" `isPrefixOf` dstDir) -> do
forM_ files $ \file -> do
let dst = dstDir </> file
src = srcDir </> file