From 5b36fea95cc94975d67067a3d01c92c7f49098dd Mon Sep 17 00:00:00 2001 From: Javran Cheng Date: Thu, 24 Sep 2015 15:26:01 -0400 Subject: prevent "-h" or "--help" from generating dir assume user in general is not expecting "--something" directory to be generated. --- src/Hakyll/Init.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Hakyll/Init.hs b/src/Hakyll/Init.hs index 9d90f31..816ef43 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,7 @@ main = do files <- getRecursiveContents (const $ return False) srcDir case args of - [dstDir] -> do + [dstDir] | not ("-" `isPrefixOf` dstDir) -> do forM_ files $ \file -> do let dst = dstDir file src = srcDir file -- cgit v1.2.3 From 9c9fe95a3580307215d76f130102729c5bb521c9 Mon Sep 17 00:00:00 2001 From: Javran Cheng Date: Fri, 25 Sep 2015 07:28:53 -0400 Subject: guard explained --- src/Hakyll/Init.hs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/Hakyll/Init.hs b/src/Hakyll/Init.hs index 816ef43..71055f0 100644 --- a/src/Hakyll/Init.hs +++ b/src/Hakyll/Init.hs @@ -31,6 +31,12 @@ main = do files <- getRecursiveContents (const $ return False) srcDir case args of + -- 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 -- cgit v1.2.3