-- Copyright: 2009 Dino Morelli
-- License: BSD3 (see LICENSE)
-- Author: Dino Morelli <dino@ui3.info>

module Cargs.Conf
   ( confToCommand )
   where

import Data.List ( intercalate, isPrefixOf )


{- Take config file contents, remove any blank lines and comments, 
   assemble the remains into a space-delimited command-line string.
-}
confToCommand :: String -> String
confToCommand entireConf =
   intercalate " " $ filter noComments $ lines entireConf

   where
      -- Return false if the line has any of these characteristics
      noComments l = all (== True) $ map (\f -> f l)
         [ (/= "")                 -- Blank lines
         , (not . isPrefixOf "#")  -- Lines starting with #
         ]

