<commit_before>module Main
  ( main
  ) where

import Protolude

import qualified Data.Text as T

import Ethereum.Analyzer.Debug
import Ethereum.Analyzer.Solidity

import Options.Applicative
import Options.Applicative.Text

data AnalyzeFlags = AnalyzeFlags
  { astJson :: Text
  , debug :: Bool
  } deriving (Eq, Show)

analyzeFlags :: Parser AnalyzeFlags
analyzeFlags =
  AnalyzeFlags <$>
  textOption
    (long "astJson" <> metavar "PATH" <> help "Path to the ast-json file.") <*>
  switch (long "debug" <> help "Whether to print debug info")

main :: IO ()
main = analyze =<< execParser opts
  where
    opts =
      info
        (analyzeFlags <**> helper)
        (fullDesc <>
         progDesc (toS ("Analyze the contract specified at PATH" :: Text)) <>
         header
           (toS ("ea-analyze - CLI interface for ethereum-analyzer" :: Text)))

analyze :: AnalyzeFlags -> IO ()
analyze flags@AnalyzeFlags {astJson = theAstJson} = do
  putText $ show flags
  content <- readFile $ toS theAstJson
  case decodeContracts content of
    Right contracts -> do
      pprintContracts contracts
      putText "Findins: \n"
      putText ("\n" `T.intercalate` concatMap findingsFor contracts)
    Left err -> putText err
  return ()
<commit_msg>Accepts stdin.<commit_after>module Main
  ( main
  ) where

import Protolude

import qualified Data.Text as T

import Ethereum.Analyzer.Debug
import Ethereum.Analyzer.Solidity hiding (value)

import Options.Applicative
import Options.Applicative.Text

data AnalyzeFlags = AnalyzeFlags
  { astJson :: Text
  , debug :: Bool
  } deriving (Eq, Show)

analyzeFlags :: Parser AnalyzeFlags
analyzeFlags =
  AnalyzeFlags <$>
  textOption
    (long "astJson" <> value "" <> metavar "PATH" <>
     help "Path to the ast-json file.") <*>
  switch (long "debug" <> help "Whether to print debug info")

main :: IO ()
main = analyze =<< execParser opts
  where
    opts =
      info
        (analyzeFlags <**> helper)
        (fullDesc <>
         progDesc (toS ("Analyze the contract specified at PATH" :: Text)) <>
         header
           (toS ("ea-analyze - CLI interface for ethereum-analyzer" :: Text)))

analyze :: AnalyzeFlags -> IO ()
analyze flags@AnalyzeFlags { astJson = theAstJson
                           , debug = debug } = do
  putText $ show flags
  content <- if (theAstJson == "" || theAstJson == "-")
             then getContents
             else readFile $ toS theAstJson
  case decodeContracts content of
    Right contracts -> do
      when debug $ pprintContracts contracts
      putText "Findings: \n"
      putText ("\n" `T.intercalate` concatMap findingsFor contracts)
    Left err -> putText err
  return ()

{'fraction_non_alphanumeric': 0.10429906542056075, 'fraction_numerical': 0.0, 'mean_word_length': 2.9295154185022025, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '404776', 'n_tokens_mistral': 850, 'n_tokens_neox': 799, 'n_words': 256}