Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CliParser: don't suggest hidden options #129

Merged
merged 2 commits into from
May 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ class HelpCommand(
}

def notRecognized(subcommand: String, app: CliApp): Int = {
val closestSubcommand =
Levenshtein.closestCandidate(subcommand, app.commands.map(_.name))
val commands = app.commands.filter(!_.isHidden).map(_.name)
val closestSubcommand = Levenshtein.closestCandidate(subcommand, commands)
val didYouMean = closestSubcommand match {
case None => ""
case Some(candidate) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ final class Settings[T](
} yield deprecation).headOption
}
def names: List[String] = settings.map(_.name)
def nonHiddenNames: List[String] = settings.flatMap { x =>
if (x.isHidden) None else Some(x.name)
}
def allNames: List[String] =
for {
setting <- settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CliParser[T](
settings.settings.find(_.isCatchInvalidFlags) match {
case None =>
val closestCandidate =
Levenshtein.closestCandidate(camel, settings.names)
Levenshtein.closestCandidate(camel, settings.nonHiddenNames)
val didYouMean = closestCandidate match {
case None =>
""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object NoTyposDecoder {
key -> obj.pos
}
ConfError
.invalidFieldsOpt(typos, ev.settings.map(_.name))
.invalidFieldsOpt(typos, ev.nonHiddenNames)
.fold(otherwise)(_.notOk)
}(conf)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,12 @@ class CliParserSuite extends BaseCliParserSuite {
|""".stripMargin
)

checkError(
"skip hidden",
"--hidden1" :: "10" :: Nil,
"""|found argument '--hidden1' which wasn't expected, or isn't valid in this context.
| Did you mean '--in'?
|""".stripMargin
)

}