Kotlin/kotlinx-cli

Nested Subcommand and Argument for parent Command are conflicting

Closed this issue · 2 comments

when I determine nested subcommands like below, arguments are conflicted with nested subcommands.

// parent subcommand
class ParentCommand: Subcommand("parent", "parent command") {
   val arg by argument(
      ArgType.String,
      "arg",
      "arg description"
  ).required()

  init {
     val child = ChildCommand()
     subcommands(child)
  }

   override fun execute() {}
}

// nested subcommand 
class ChildCommand: Subcommand("child", "child command") {
   override fun execute() {}
}
command parent child
# this will not execute child command but print error message which says argument is missing

Is this expected behaviour? or am I missing something here?

It's expected. Problem is that you set argument as required, this means that this argument should be always provided in command line. To make command command parent child valid you have to make argument argument optional

val compareToReport by argParser.argument(ArgType.String, description = "Report to compare to").optional()

Ok I understand that.

I know it's still experimental but it might be great to be documented.

Anyway thanks for the explanation.
Link to the test code was really helpful to understand.