<commit_before>{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE RecordWildCards #-}
module Main (main) where

import System.Console.CmdArgs.Implicit

import Data.Whisper

main :: IO ()
main = (runCmd =<<) . cmdArgs $
  modes
    [ cmdInfo
    , cmdPush
    ]
  &= summary versionString
  &= program "curved"

-- | String with the program name, version and copyright.
versionString :: String
versionString =
  "Curved. Copyright (c) 2012 <NAME>."
  -- TODO add the version.

-- | Data type representing the different command-line subcommands.
data Cmd =
    Info { cmdFilename :: FilePath }
    -- ^ Display some Whisper file information.
  | Push
    -- ^ Add a new timestamped value to a Whisper file.
  deriving (Data, Typeable)

-- | Create a 'Info' command.
cmdInfo :: Cmd
cmdInfo = Info
  { cmdFilename = def
    &= argPos 0
    &= typ "FILE"
  } &= help "Display some Whisper file information."
    &= explicit
    &= name "info"

-- | Create a 'Push' command.
cmdPush :: Cmd
cmdPush = Push
    &= help "Add a new timestamped value to a Whisper file."
    &= explicit
    &= name "push"

-- | Run a sub-command.
runCmd :: Cmd -> IO ()
runCmd Info{..} = do
  wsp <- openWhisper cmdFilename
  header <- readHeader wsp
  print header
  archives <- readArchives wsp
  print archives
  closeWhisper wsp<commit_msg>Slightly better `info` output.<commit_after>{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE RecordWildCards #-}
module Main (main) where

import Data.Char (toLower)
import System.Console.CmdArgs.Implicit

import Data.Whisper

main :: IO ()
main = (runCmd =<<) . cmdArgs $
  modes
    [ cmdInfo
    , cmdPush
    ]
  &= summary versionString
  &= program "curved"

-- | String with the program name, version and copyright.
versionString :: String
versionString =
  "Curved. Copyright (c) 2012 <NAME>."
  -- TODO add the version.

-- | Data type representing the different command-line subcommands.
data Cmd =
    Info { cmdFilename :: FilePath }
    -- ^ Display some Whisper file information.
  | Push
    -- ^ Add a new timestamped value to a Whisper file.
  deriving (Data, Typeable)

-- | Create a 'Info' command.
cmdInfo :: Cmd
cmdInfo = Info
  { cmdFilename = def
    &= argPos 0
    &= typ "FILE"
  } &= help "Display some Whisper file information."
    &= explicit
    &= name "info"

-- | Create a 'Push' command.
cmdPush :: Cmd
cmdPush = Push
    &= help "Add a new timestamped value to a Whisper file."
    &= explicit
    &= name "push"

-- | Run a sub-command.
runCmd :: Cmd -> IO ()
runCmd Info{..} = do
  wsp <- openWhisper cmdFilename
  Header{..} <- readHeader wsp
  let MetaData{..} = hMetaData
  closeWhisper wsp

  putStrLn $ cmdFilename ++ ": period=" ++ show mdMaxRetention
    ++ ", aggregation=" ++ map toLower (show mdAggregationType)
    ++ ", propagation=" ++ show mdXFilesFactor
    ++ ", archives=" ++ show mdArchiveCount
  let f ai@ArchiveInfo{..} = "  period=" ++ show (aiRetention ai)
        ++ ", points=" ++ show aiPoints
        ++ ", seconds=" ++ show aiSecondsPerPoint
        ++ ", size=" ++ show (aiSize ai)
        ++ ", offset=" ++ show aiOffset
  mapM_ (putStrLn . f) hArchiveInfo
{'fraction_non_alphanumeric': 0.12938177182919056, 'fraction_numerical': 0.0031867431485022306, 'mean_word_length': 2.9335839598997495, 'pattern_counts': {'":': 1, '<': 14, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4387679', 'n_tokens_mistral': 1021, 'n_tokens_neox': 995, 'n_words': 327}