diff --git a/cabal-gild.cabal b/cabal-gild.cabal
--- a/cabal-gild.cabal
+++ b/cabal-gild.cabal
@@ -11,7 +11,7 @@
 maintainer: Taylor Fausak
 name: cabal-gild
 synopsis: Formats package descriptions.
-version: 1.1.3.0
+version: 1.1.4.0
 
 source-repository head
   type: git
diff --git a/source/library/CabalGild/Main.hs b/source/library/CabalGild/Main.hs
--- a/source/library/CabalGild/Main.hs
+++ b/source/library/CabalGild/Main.hs
@@ -20,7 +20,6 @@
 import qualified CabalGild.Type.Config as Config
 import qualified CabalGild.Type.Context as Context
 import qualified CabalGild.Type.Flag as Flag
-import qualified CabalGild.Type.Input as Input
 import qualified CabalGild.Type.Leniency as Leniency
 import qualified CabalGild.Type.Mode as Mode
 import qualified Control.Monad as Monad
@@ -67,26 +66,8 @@
   config <- Config.fromFlags flags
   context <- Context.fromConfig config
 
-  let source = Context.input context
-  input <- MonadRead.read source
-  fields <-
-    either (Exception.throwM . ParseError.ParseError) pure $
-      Fields.readFields input
-  let csv = GetCabalVersion.fromFields fields
-      comments = ExtractComments.fromByteString input
-      path = case source of
-        Input.Stdin -> Context.stdin context
-        Input.File f -> f
-  output <-
-    ( StripBlanks.run
-        Monad.>=> AttachComments.run
-        Monad.>=> ReflowText.run csv
-        Monad.>=> RemovePositions.run
-        Monad.>=> EvaluatePragmas.run path
-        Monad.>=> FormatFields.run csv
-        Monad.>=> Render.run
-      )
-      (fields, comments)
+  input <- MonadRead.read $ Context.input context
+  output <- format (Context.stdin context) input
 
   case Context.mode context of
     Mode.Check -> do
@@ -97,6 +78,29 @@
                in output == ByteString.replace crlf lf input
             Leniency.Strict -> output == input
       Monad.unless formatted $ Exception.throwM CheckFailure.CheckFailure
-    Mode.Format -> do
-      let target = Context.output context
-      MonadWrite.write target output
+    Mode.Format -> MonadWrite.write (Context.output context) output
+
+-- | Formats the given input using the provided file path as the apparent
+-- source file (see 'Context.stdin'). An exception will be thrown if the input
+-- is invalid. The 'MonadWalk.MonadWalk' constraint is used to discover modules
+-- on the file system. Typically @m@ will be 'IO'.
+format ::
+  (Exception.MonadThrow m, MonadWalk.MonadWalk m) =>
+  FilePath ->
+  ByteString.ByteString ->
+  m ByteString.ByteString
+format filePath input = do
+  fields <-
+    either (Exception.throwM . ParseError.ParseError) pure $
+      Fields.readFields input
+  let csv = GetCabalVersion.fromFields fields
+      comments = ExtractComments.fromByteString input
+  ( StripBlanks.run
+      Monad.>=> AttachComments.run
+      Monad.>=> ReflowText.run csv
+      Monad.>=> RemovePositions.run
+      Monad.>=> EvaluatePragmas.run filePath
+      Monad.>=> FormatFields.run csv
+      Monad.>=> Render.run
+    )
+    (fields, comments)
diff --git a/source/library/CabalGild/Type/Context.hs b/source/library/CabalGild/Type/Context.hs
--- a/source/library/CabalGild/Type/Context.hs
+++ b/source/library/CabalGild/Type/Context.hs
@@ -73,11 +73,15 @@
           Exception.throwM SpecifiedCrlfWithFormatMode.SpecifiedCrlfWithFormatMode
     _ -> pure ()
 
+  let theInput = Optional.withDefault Input.Stdin $ Config.input config
+      filePath = case theInput of
+        Input.Stdin -> "."
+        Input.File f -> f
   pure
     Context
       { crlf = Optional.withDefault Leniency.Lenient $ Config.crlf config,
-        input = Optional.withDefault Input.Stdin $ Config.input config,
+        input = theInput,
         mode = Optional.withDefault Mode.Format $ Config.mode config,
         output = Optional.withDefault Output.Stdout $ Config.output config,
-        stdin = Optional.withDefault "." $ Config.stdin config
+        stdin = Optional.withDefault filePath $ Config.stdin config
       }
