Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-786

Use "withRequiredArg" while parsing jopt options in all tools

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • None
    • 0.8.0
    • None

    Description

      While parsing jopt Options in our tools, we sometimes use withRequiredArg() and sometimes use withOptionalArg(). I think this confusing and we should always use withRequiredArg().

      withOptionalArg() allows you to provide an option without an argument. For instance, the following commands will yield the same result if xyz was a parser option that accepted an optional argument and was provided a default in the tool's code:
      kafka-tool.sh --xyz
      kafka-tool.sh

      I don't quite see the need to allow the 1st command, think that writing code will be less confusing if we allowed only the second command. To do that, we can make all options require arguments. These arguments will need to be given via command line or via a default in the code. So if xyz was an option that required an argument then you will see the following:

      kafka-tool.sh --xyz
      Option ['xyz'] requires an argument //printed by jOpt

      kafka-tool.sh --xyz argumentVal
      // Kafka tool proceeds

      If you want to use a default value specified for xyz in the code, then simply run ./kafka-tool.sh.

      Attachments

        1. kafka-786.patch
          5 kB
          Swapnil Ghike
        2. kafka-786-v2.patch
          5 kB
          Swapnil Ghike

        Activity

          People

            swapnilghike Swapnil Ghike
            swapnilghike Swapnil Ghike
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: