Skip to content

Instantly share code, notes, and snippets.

@JordanMartinez
Created April 24, 2019 17:50
Show Gist options
  • Save JordanMartinez/7ff1af377dfcddf885aad8cd17fb16c3 to your computer and use it in GitHub Desktop.
Save JordanMartinez/7ff1af377dfcddf885aad8cd17fb16c3 to your computer and use it in GitHub Desktop.
Tracking down OptParse help text slowdown
module TestOP where
import Prelude
import Data.Array (filter, intercalate)
import Data.Array as Array
import Data.Either (Either(..))
import Data.String (Pattern(..), split)
import Data.String as String
import Effect (Effect)
import Effect.Console (log)
import Options.Applicative (Parser, ParserInfo, eitherReader, execParser, fullDesc, help, helper, info, long, metavar, option, progDesc, short, showDefault, showDefaultWith, strOption, switch, value)
import Options.Applicative.Types (ReadM)
main :: Effect Unit
main = do
log "Now running test"
result <- execParser parseCLIArgs
log "done"
parseCLIArgs :: ParserInfo Unit
parseCLIArgs =
info
( helper <*> argParser )
( fullDesc
<> progDesc "Produces a Table of Contents file in Markdown whose links \
\refer to a GitHub repo's corresponding file."
)
argParser :: Parser Unit
argParser = ado
-- works up til 5 arguments
-- starts to slowdown at 6 and greatly slows down at 7
rootDir <- parseRootDir
outputFile <- parseOutputFile
username <- parseGitHubUsername
project <- parseGitHubProject
ref <- parseGitHubRef
logLevel <- parseLogLevel
skipUrlCheck <- parseSkipUrlCheck
-- excludedTopLevelDirs <- parseExcludedTopLevelDirs
-- excludedRegularDir <- parseExcludedRegularDirs
-- includedFileExtensions <- parseIncludedFileExtensions
in unit
where
parseRootDir :: Parser String
parseRootDir =
strOption ( long "root-dir"
<> short 'r'
<> help "The local computer's file path to the root directory \
\that contains this repository."
<> metavar "ROOT_DIR"
)
parseOutputFile :: Parser String
parseOutputFile =
strOption ( long "output-file"
<> short 'o'
<> help "The path of the file to which to write the \
\program's Table of Contents output"
<> metavar "OUTPUT_FILE"
)
multiString :: ReadM (Array String)
multiString = eitherReader \s ->
let strArray = filter String.null $ split (Pattern ",") s
in
if Array.null strArray
then Left "got empty string as input"
else Right strArray
parseExcludedTopLevelDirs :: Parser (Array String)
parseExcludedTopLevelDirs =
option multiString
( long "exclude-top-level-dirs"
<> short 't'
<> metavar "DIR1,DIR2,...,DIR3"
<> help "A comma-separated list of top-level directories \
\(case-sensitive) to exclude."
<> value [ ".git", ".github", ".procedures", ".travis", "output"]
<> showDefaultWith (\array -> intercalate "," array)
)
parseExcludedRegularDirs :: Parser (Array String)
parseExcludedRegularDirs =
option multiString
( long "exclude-regular-dirs"
<> short 'd'
<> metavar "DIR1,DIR2,...,DIR3"
<> help "A comma-separated list of regular directories \
\(case-sensitive) to exclude."
<> value
-- PS-related directories
[ ".spago", "generated-docs", ".psci_modules", "output", "tmp"
-- NPM and Parcel related things
, ".cache", "node_modules", "dist"
-- project-specific files
, "benchmark-results"
-- repo-specific files
, "assets", "modules-used-in-examples"
]
<> showDefaultWith (\array -> intercalate "," array)
)
parseIncludedFileExtensions :: Parser (Array String)
parseIncludedFileExtensions =
option multiString
( long "include-files-with-extensions"
<> short 'f'
<> metavar ".EXT1,.EXT2,...,.EXT3"
<> help "A comma-separated list of file extensions \
\that should be included in the Table of Contents."
<> value [ ".purs", ".md", ".js"]
<> showDefaultWith (\array -> intercalate "," array)
)
parseGitHubUsername :: Parser String
parseGitHubUsername =
strOption ( long "github-username"
<> short 'u'
<> help "The username part of the GitHub repository's URL."
<> metavar "USERNAME"
<> value "JordanMartinez"
<> showDefault
)
parseGitHubProject :: Parser String
parseGitHubProject =
strOption ( long "github-project"
<> short 'p'
<> help "The project name part of the GitHub repository's URL."
<> metavar "PROJECT_NAME"
<> value "purescript-jordans-reference"
<> showDefault
)
parseGitHubRef :: Parser String
parseGitHubRef =
strOption ( long "github-reference"
<> help "The name of the project's branch or tag to use when \
\producing the hyperlinks to files and their headers."
<> metavar "TAG_OR_BRANCH"
<> value "development"
<> showDefault
)
parseLogLevel :: Parser String
parseLogLevel =
strOption ( long "log-level"
<> help "The amount of information to log to the screen. \
\Valid options are 'error', 'info', and 'debug'."
<> metavar "LOG_LEVEL"
<> value "error"
<> showDefault
)
parseSkipUrlCheck :: Parser Boolean
parseSkipUrlCheck =
switch ( long "skip-url-verification"
<> help "Do not verify whether hyperlinks work, \
\but still render the ToC file with them."
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment