Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Check file names.

  • Loading branch information...
commit a02105eced862f839772eb9459e99d5c6968fac8 1 parent 1cb9bc5
@bjornbm authored
Showing with 36 additions and 3 deletions.
  1. +36 −3 nn.hs
View
39 nn.hs
@@ -21,18 +21,20 @@ import Text.Regex.TDFA
data NN = List { all :: Bool, exec :: Maybe String, terms :: [String] }
| Cat { iD :: String }
| Tags { popularity :: Bool }
+ | Check { names :: Bool, references :: Bool }
| Junk
deriving (Show, Data, Typeable)
main = do
- mode <- cmdArgs (modes [listMode &= auto, catMode, tagsMode])
+ mode <- cmdArgs (modes [listMode &= auto, catMode, tagsMode, checkMode])
dir <- getEnv "NN_HOME"
setCurrentDirectory dir
case mode of
List _ _ _ -> list mode
Cat _ -> print mode
Tags _ -> tags mode
+ Check _ _ -> check mode
otherwise -> list mode
@@ -43,9 +45,12 @@ listMode = List { exec = def &= help "Pass files as arguments to COMMAND" &= typ
}
catMode = Cat { iD = def &= args &= typ "FILE ID" }
tagsMode = Tags { popularity = def &= help "Show and sort by the popularity of tags" }
+checkMode = Check { names = def &= help "List badly named files"
+ , references = def &= help "List files containing bad file references"
+ }
-- List the names of files matching the terms.
-list (List _ Nothing terms) = putStr . unlines =<< getFiles terms
+list (List _ Nothing terms) = mapM_ putStrLn =<< getFiles terms
-- Apply command specified with --exec to files matching the terms.
list (List _ (Just exec) terms) = do
@@ -59,7 +64,35 @@ list (List _ (Just exec) terms) = do
tags (Tags pop) = do
ts <- countTags <$> getFiles []
if pop then mapM_ (uncurry (printf "%3d %s\n")) $ reverse $ sort ts
- else putStr $ unlines $ map snd ts
+ else mapM_ putStrLn $ map snd ts
+
+-- List files with bad names.
+check (Check True False) = do
+ files <- mdlist
+ mapM_ putStrLn $ sort
+ $ filter (/= ".")
+ $ filter (/= "..")
+ $ filter (not . (=~ filePattern'))
+ $ fmap takeFileName files
+
+-- List files with bad references.
+check (Check False True) = do
+ putStrLn "NOT IMPLEMENTED" -- TODO
+
+-- List bad files with headers.
+check (Check False False) = do
+ putStrLn "Badly named files"
+ putStrLn "-----------------"
+ check (Check True False)
+ putStrLn ""
+ putStrLn "Files with bad references"
+ putStrLn "-------------------------"
+ check (Check False True)
+
+check (Check True True) = do
+ check (Check True False)
+ check (Check False True)
+
getFiles [] = do
Please sign in to comment.
Something went wrong with that request. Please try again.