retrie-1.2.2: A powerful, easy-to-use codemodding tool for Haskell.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Retrie.Options

Contents

- Options
- Internal

Synopsis

- type Options = Options_ [Rewrite Universe] AnnotatedImports
- data Options_ rewrites imports = Options {
  - additionalImports :: imports
  - colorise :: ColoriseFun
  - elaborations :: rewrites
  - executionMode :: ExecutionMode
  - extraIgnores :: [FilePath]
  - fixityEnv :: FixityEnv
  - iterateN :: Int
  - noDefaultElaborations :: Bool
  - randomOrder :: Bool
  - rewrites :: rewrites
  - roundtrips :: [RoundTrip]
  - singleThreaded :: Bool
  - targetDir :: FilePath
  - targetFiles :: [FilePath]
  - verbosity :: Verbosity
  }
- data ExecutionMode
  - = ExecDryRun
  - | ExecRewrite
  - | ExecExtract
  - | ExecSearch
- defaultOptions :: (Default rewrites, Default imports) => FilePath -> Options_ rewrites imports
- parseOptions :: LibDir -> FixityEnv -> IO Options
- buildGrepChain :: FilePath -> HashSet String -> [FilePath] -> GrepCommands
- forFn :: Options_ x y -> [a] -> (a -> IO b) -> IO [b]
- getOptionsParser :: FixityEnv -> IO (Parser ProtoOptions)
- getTargetFiles :: Options_ a b -> [GroundTerms] -> IO [FilePath]
- parseRewritesInternal :: LibDir -> Options_ a b -> [RewriteSpec] -> IO [Rewrite Universe]
- parseVerbosity :: Verbosity -> Parser Verbosity
- type ProtoOptions = Options_ [RewriteSpec] [String]
- resolveOptions :: LibDir -> ProtoOptions -> IO Options
- data GrepCommands = GrepCommands {
  - initialFileSet :: [FilePath]
  - commandChain :: [CommandLine]
  }

# Options

type Options = Options_ [Rewrite Universe] AnnotatedImports #

Command-line options.

data Options_ rewrites imports #

Constructors

Options |

Fields

- additionalImports :: imports

  Imports specified by the command-line flag '--import'.

- colorise :: ColoriseFun

  Function used to colorize results of certain execution modes.

- elaborations :: rewrites

  Rewrites which are applied to the left-hand side of the actual rewrites.

- executionMode :: ExecutionMode

  Controls behavior of `apply`. See `ExecutionMode`.

- extraIgnores :: [FilePath]

  Specific files that should be ignored. Paths should be relative to `targetDir`.

- fixityEnv :: FixityEnv

  Fixity information for operators used during parsing (of rewrites and target modules). Defaults to base fixities.

- iterateN :: Int

  Iterate the given rewrites or `Retrie` computation up to this many times. Iteration may stop before the limit if no changes are made during a given iteration.

- noDefaultElaborations :: Bool

  Do not apply any of the built in elaborations in `defaultElaborations`.

- randomOrder :: Bool

  Whether to randomize the order of target modules before rewriting them.

- rewrites :: rewrites

  Rewrites specified by command-line flags such as '--adhoc'.

- roundtrips :: [RoundTrip]

  Paths that should be roundtripped through ghc-exactprint to debug. Specified by the '--roundtrip' command-line flag.

- singleThreaded :: Bool

  Whether to concurrently rewrite target modules. Mostly useful for viewing debugging output without interleaving it.

- targetDir :: FilePath

  Directory that contains the code being targeted for rewriting.

- targetFiles :: [FilePath]

  Instead of targeting all Haskell files in `targetDir`, only target specific files. Paths should be relative to `targetDir`.

- verbosity :: Verbosity

  How much should be output on `stdout`.

data ExecutionMode #

Controls the ultimate action taken by `apply`. The default action is `ExecRewrite`.

Constructors

ExecDryRun | Pretend to do rewrites, show diff.
ExecRewrite | Perform rewrites.
ExecExtract | Print the resulting expression for each match.
ExecSearch | Print the matched expressions.

#### Instances

Instances details

Show ExecutionMode # |
Instance details Defined in Retrie.Options Methods showsPrec :: Int -> ExecutionMode -> ShowS show :: ExecutionMode -> String showList :: [ExecutionMode] -> ShowS

defaultOptions :: (Default rewrites, Default imports) => FilePath -> Options_ rewrites imports #

Construct default options for the given target directory.

parseOptions :: LibDir -> FixityEnv -> IO Options #

Parse options using the given `FixityEnv`.

# Internal

buildGrepChain :: FilePath -> HashSet String -> [FilePath] -> GrepCommands #

Return a chain of grep commands to find files with relevant groundTerms If filesGiven is empty, use all *.hs files under targetDir

forFn :: Options_ x y -> [a] -> (a -> IO b) -> IO [b] #

`forM`, but concurrency and input order controled by `Options`.

getOptionsParser :: FixityEnv -> IO (Parser ProtoOptions) #

Get the options parser. The returned `ProtoOptions` should be passed to `resolveOptions` to get final `Options`.

getTargetFiles :: Options_ a b -> [GroundTerms] -> IO [FilePath] #

Find all files to target for rewriting.

parseRewritesInternal :: LibDir -> Options_ a b -> [RewriteSpec] -> IO [Rewrite Universe] #

Create `Rewrite`s from string specifications of rewrites. We expose this from Retrie with a nicer type signature as `parseRewrites`. We have it here so we can use it with `ProtoOptions`.

parseVerbosity :: Verbosity -> Parser Verbosity #

Parser for `Verbosity`.

type ProtoOptions = Options_ [RewriteSpec] [String] #

Options that have been parsed, but not fully resolved.

resolveOptions :: LibDir -> ProtoOptions -> IO Options #

Resolve `ProtoOptions` into `Options`. Parses rewrites into `Rewrite`s, parses imports, validates options, and extends `fixityEnv` with any declared fixities in the target directory.

data GrepCommands #

Constructors

GrepCommands |

Fields

- initialFileSet :: [FilePath]
- commandChain :: [CommandLine]

#### Instances

Instances details

Show GrepCommands # |
Instance details Defined in Retrie.Options Methods showsPrec :: Int -> GrepCommands -> ShowS show :: GrepCommands -> String showList :: [GrepCommands] -> ShowS
Eq GrepCommands # |
Instance details Defined in Retrie.Options Methods (==) :: GrepCommands -> GrepCommands -> Bool (/=) :: GrepCommands -> GrepCommands -> Bool