buildCommandString :: Command -> [(String, String)] -> Maybe String
buildCommandString cmd args = result
   where
      result = case listArgs cmd of
         Just cmdArgs -> if (hasAllArgs cmdArgs) then Just insertValues else Nothing
         Nothing -> Nothing
      hasAllArgs cmdArgs = (sort cmdArgs) == (sort (map fst args))

      insertValues = foldl addArg cmdTemplate args
      addArg str (name, value) = replace str ("%%" ++ name ++ "%%") value
      Command _ cmdTemplate = cmd
buildCommandString :: Command -> [(String, String)] -> Maybe String
buildCommandString cmd args = result
   where
      result = case listArgs cmd of
         Just cmdArgs -> if (hasAllArgs cmdArgs) then Just insertValues else Nothing
         Nothing -> Nothing
      hasAllArgs cmdArgs = (sort cmdArgs) == (sort (map fst args))

      insertValues = foldl addArg cmdTemplate args
      addArg str (name, value) = replace str ("%%" ++ name ++ "%%") value
      Command _ cmdTemplate = cmd
buildCommandString cmd args = result
   where
      result = case listArgs cmd of
         Just cmdArgs -> if (hasAllArgs cmdArgs) then Just insertValues else Nothing
         Nothing -> Nothing
      hasAllArgs cmdArgs = (sort cmdArgs) == (sort (map fst args))

      insertValues = foldl addArg cmdTemplate args
      addArg str (name, value) = replace str ("%%" ++ name ++ "%%") value
      Command _ cmdTemplate = cmd