<commit_before>module Lycopene.Option.Common
        ( CommonOption(..)
        , commonOption
        , configure
        ) where

import           System.FilePath
import           Options.Applicative
import           Lycopene.Configuration

data CommonOption = CommonOption
                   { verbose :: Bool
                   , homeLocation :: FilePath
                   }

commonOption :: Parser CommonOption
commonOption = CommonOption <$> optionP <*> lycoHomeP where
  optionP = switch
          (  short 'v'
          <> long "verbose"
          <> help "Set to print verbosely ")
  lycoHomeP = option auto
          (  short 'c'
          <> long "context"
          <> help "Set lycopene home directory path as context"
          <> value ("~" </> ".lyco" :: FilePath) )
 
configure :: CommonOption -> Configuration
configure co = Configuration
               { lycoHome = homeLocation co
               }

<commit_msg>add operation on platform to build common option data<commit_after>module Lycopene.Option.Common
        ( CommonOption(..)
        , commonOption
        , configure
        , commonOptsWithHome
        ) where

import           System.FilePath
import           Options.Applicative
import           Lycopene.Configuration

home :: FilePath
home = "~" ++ [pathSeparator]


data CommonOption = CommonOption
                   { verbose :: Bool
                   , homeLocation :: FilePath
                   , global :: Bool
                   }

commonOption :: Parser CommonOption
commonOption = CommonOption <$> optionP <*> lycoHomeP <*> globalP where
  optionP = switch
          (  short 'v'
          <> long "verbose"
          <> help "Set to print verbosely ")
  lycoHomeP = option auto
          (  short 'c'
          <> long "context"
          <> help "Set lycopene home directory path as context"
          <> value ("~" </> ".lyco" :: FilePath) )
  globalP = switch
          (  short 'g'
          <> long "global"
          <> help "Use global context") 

configure :: CommonOption -> Configuration
configure co = Configuration
               { lycoHome = home
               , datapath = home </> "issue.db"
               , contextName = Nothing
               }
  where
    home = homeLocation co

type HomePath = FilePath

commonOptsWithHome :: CommonOption -> HomePath -> CommonOption
commonOptsWithHome commonops hp = commonops { homeLocation = expandHome } where
  expandHome = replaceHome (homeLocation commonops) hp

replaceHome :: FilePath -> HomePath -> FilePath
replaceHome fp hp
  | (firstdir fp) == home = hp </> (tailPath fp)
  | otherwise = fp
  where firstdir = head . splitPath
        tailPath = joinPath . tail . splitPath

{'fraction_non_alphanumeric': 0.09026745913818722, 'fraction_numerical': 0.0, 'mean_word_length': 1.9145021645021645, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 30, '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': '7125115', 'n_tokens_mistral': 714, 'n_tokens_neox': 689, 'n_words': 206}