You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Swapnil Ghike (JIRA)" <ji...@apache.org> on 2013/03/05 01:47:13 UTC

[jira] [Comment Edited] (KAFKA-786) Use "withRequiredArg" while parsing jopt options in all tools

    [ https://issues.apache.org/jira/browse/KAFKA-786?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13592863#comment-13592863 ] 

Swapnil Ghike edited comment on KAFKA-786 at 3/5/13 12:46 AM:
--------------------------------------------------------------

Also note that withRequiredArg() does not check if xyz has a non-null value, we still need to perform that check ourselves in the code. So, jopt will do nothing to prevent you from running into a NPE, if you ran
kafka.tool.sh and xyz was an option that required an argument, but was not provided a default value in the code.
                
      was (Author: swapnilghike):
    Also note that withRequiredArg() does not check if xyz has a non-null value, we still need to perform that check ourselves in the code. So, jopt will do nothing to prevent you from running into a NPE, if you ran
kafka.tool.sh and xyz was an optional that required an argument, but was not provided a default value in the code.
                  
> Use "withRequiredArg" while parsing jopt options in all tools
> -------------------------------------------------------------
>
>                 Key: KAFKA-786
>                 URL: https://issues.apache.org/jira/browse/KAFKA-786
>             Project: Kafka
>          Issue Type: Bug
>            Reporter: Swapnil Ghike
>            Priority: Blocker
>              Labels: kafka-0.8, p2
>
> 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.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira