Skip to content

Commit

Permalink
-z --elide-empty-files
Browse files Browse the repository at this point in the history
  • Loading branch information
AesaKamar committed Mar 14, 2023
1 parent 148a1db commit ebbaa6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/scala/InputArgs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ case class InputArgs(
outputDirectory: Option[File] = None,
inputFileInsteadOfStdin: Option[File] = None,
suppressMatched: Boolean = false,
silentMode: Boolean = false
silentMode: Boolean = false,
elideEmptyFiles: Boolean = false
)

/** Use [[OParserBuilder]] API to specify how to take input args from the
Expand Down Expand Up @@ -68,6 +69,10 @@ object InputArgs {
.optional()
.text("Quiet")
.action((_, conf) => conf.copy(silentMode = true)),
opt[Unit]('z', "elide-empty-files")
.optional()
.text("remove empty output files")
.action((_, conf) => conf.copy(elideEmptyFiles = true)),
help("help").text("prints this usage text")
)
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/Resplit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ object Resplit {
args.regexToMatch.matches(thisLine)
)
}
.filter { chunk =>
if (args.elideEmptyFiles) chunk.nonEmpty || chunk.forall(_.nonEmpty)
else true
}
.zipWithIndex
.map { (chunkOfLines, chunkNumber) =>
(
Expand Down

0 comments on commit ebbaa6e

Please sign in to comment.