<commit_before>-- -*- hindent-style: "chris-done" -*-
-- 
-- I prefer the Gibiansky style, but it is creating invalid ASTs from
-- the code below. See https://github.com/chrisdone/hindent/issues/38
-- . The Chris Done style is my second favorite, so we'll go with that
-- for the time being.

{- |
Module       : Ptk.Journal.List
Description  : `ptk journal list` command tree
Copyright    : 2014, <NAME>
License      : BSD3
Maintainer   : <NAME> <<EMAIL>>
Stability    : experimental
Portability  : Linux

-}

module Ptk.Journal.List (journalListTree, journalListHelp) where

import Control.Applicative
import qualified Data.Text.IO as Tio
import PuffyTools.Journal
import PuffyTools.Slug
import System.Console.Argument
import System.Console.Command
import System.Console.Program
import System.Directory

journalListHelp :: Action IO
journalListHelp = io $ showUsage journalListTree

journalListTree :: Commands IO
journalListTree = Node lsCommand []
  where lsCommand =
          Command "list" "List all of the available journals" listEntries
        listEntries :: Action IO
        listEntries =
          io $
          do journals <- mapM readJournalFromFile =<< listJournals
             case journals of
               [] ->
                 putStrLn "You haven't created any journals."
               js ->
                 mapM_ (Tio.putStrLn . unSlug . journalSlug) journals
        dirOption :: IO (Option FilePath)
        dirOption =
          option "d" ["dir","directory"] directory <$>
          getAppUserDataDirectory "puffytools" <*>
          pure "The directory in which to look for journals."<commit_msg>Switch back to Gibiansky style.<commit_after>{- |
Module       : Ptk.Journal.List
Description  : `ptk journal list` command tree
Copyright    : 2014, <NAME>
License      : BSD3
Maintainer   : <NAME> <<EMAIL>>
Stability    : experimental
Portability  : Linux

-}

module Ptk.Journal.List (journalListTree, journalListHelp) where

import           Control.Applicative
import qualified Data.Text.IO as Tio
import           PuffyTools.Journal
import           PuffyTools.Slug
import           System.Console.Argument
import           System.Console.Command
import           System.Console.Program
import           System.Directory

journalListHelp :: Action IO
journalListHelp = io $ showUsage journalListTree

journalListTree :: Commands IO
journalListTree = Node lsCommand []
  where
    lsCommand = Command "list" "List all of the available journals" listEntries
    listEntries :: Action IO
    listEntries = io $ do
      journals <- mapM readJournalFromFile =<< listJournals
      case journals of
        [] -> putStrLn "You haven't created any journals."
        js -> mapM_ (Tio.putStrLn . unSlug . journalSlug) journals
    dirOption :: IO (Option FilePath)
    dirOption = option "d" ["dir", "directory"] directory <$> getAppUserDataDirectory "puffytools"
                                                          <*> pure
                                                                "The directory in which to look for journals."
{'fraction_non_alphanumeric': 0.08279009126466753, 'fraction_numerical': 0.003911342894393742, 'mean_word_length': 2.4677966101694917, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1967694', 'n_tokens_mistral': 834, 'n_tokens_neox': 801, 'n_words': 268}