{"issue":{"state":"open","pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"user":{"avatar_url":"https://secure.gravatar.com/avatar/ba1e0bd260b89cd441e7940545188e57?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"ba1e0bd260b89cd441e7940545188e57","url":"https://api.github.com/users/rodionmoiseev","login":"rodionmoiseev","id":756311},"milestone":null,"labels":[],"updated_at":"2011-11-05T13:10:35Z","assignee":null,"closed_at":null,"comments":1,"url":"https://api.github.com/repos/cbeust/jcommander/issues/84","body":"This is a problem I have bumped into after my software got fairly large and the number of commands and options got bigger. \r\n\r\nMy software mainly utilizes commands feature. For each of my commands I have a corresponding class that holds all the necessary option fields. As some commands share sets of options, I have been using inheritance to remove duplication of option declaration. But now I am facing more complex combinations of options sharing, and inheritance is no longer enough, because in Java you can only inherit from one class.\r\n\r\nI have come-up with a fairly simple solution: delegates (or mixins). The idea is to be able to share options like this:\r\n\r\n    //For commands that provide help option\r\n    class Help {\r\n      @Parameter(names=\"-h\")\r\n      public boolean help;\r\n    }\r\n\r\n    //For commands that require repository to be specified\r\n    class UseRepository{\r\n      @Parameter(names=\"-r\", required = true)\r\n      public String repo = \"/default/repo/location\"\r\n    }\r\n\r\n    //Upload command\r\n    class UploadCmd{\r\n      @ParametersDelegate\r\n      public Help helpOpts = new Help();\r\n      @ParametersDelegate\r\n      public UseRepository repoOpts = new UseRepository();\r\n      @Parameter(name=\"-f\")\r\n      public boolean force;\r\n    }\r\n\r\n    //usage (nothing new here)\r\n    UploadCmd uc = new UploadCmd();\r\n    jcommander.addCommand(\"upload\", uc);\r\n    jcommander.parse(args);\r\n\r\n    //check if help is set\r\n    if(uc.helpOpts.help){\r\n      usage();\r\n    }\r\n\r\nThis allows you to share options in a more flexible way, without using inheritance. \r\n\r\nBy the way, I have noticed that `JCommander` supports adding any number of objects, so that in theory I should be able to achieve the same effect. However, firstly it didn't appear to work (adding another object overrode the first one), which is probably just a bug, and secondly, it would be not very elegant to do\r\n\r\n    UploadCmd uc = new UploadCmd();\r\n    jcommander.addCommand(\"upload\", uc);\r\n    JCommander uc_command = jcommander.getCommands().get(\"upload\");\r\n    uc_command.addObject(uc.helpOpts);\r\n    uc_command .addObject(uc.repoOpts);\r\n\r\nI have already implemented this feature in one of my branches (very simple fix), but it would be nice to hear your opinion on this first.\r\n\r\nRegards.","html_url":"https://github.com/cbeust/jcommander/issues/84","title":"Add delegate (mixin) functionality for creating complex command options","number":84,"id":2151502,"created_at":"2011-11-05T11:12:04Z"},"action":"created","comment":{"user":{"avatar_url":"https://secure.gravatar.com/avatar/97a472a751e503a7f8e5d88ba087a87c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"97a472a751e503a7f8e5d88ba087a87c","url":"https://api.github.com/users/cbeust","login":"cbeust","id":92322},"updated_at":"2011-11-05T13:10:35Z","url":"https://api.github.com/repos/cbeust/jcommander/issues/comments/2640341","body":"Sounds like a good idea. JCommander could simply go through all the arg objects and whenever it encounters a @ParameterDelegate annotation, it adds the arg object so you don't have to.","id":2640341,"created_at":"2011-11-05T13:10:35Z"}}