You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jlm429 <gi...@git.apache.org> on 2017/06/17 23:10:41 UTC

[GitHub] commons-cli pull request #14: Added BugCLI260 JUnit Test

GitHub user jlm429 opened a pull request:

    https://github.com/apache/commons-cli/pull/14

    Added BugCLI260 JUnit Test

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/jlm429/commons-cli master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/commons-cli/pull/14.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #14
    
----
commit a2b142847c452f27462575cce3534ef534796b69
Author: John Mansfield <jm...@gatech.edu>
Date:   2017-06-17T22:03:54Z

    Added BugCLI260 JUnit Test

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by jlm429 <gi...@git.apache.org>.
Github user jlm429 commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    Just adding this diff from the code above if needed for future reference.  this pr can be closed - do we possibly need more committers for CLI?  It doesn't seem like anyone is paying attention to the 2 that are open... 
    
    @@ -540,10 +539,32 @@ else if (isJavaProperty(t))
                 String opt = t.substring(0, pos);
                 String value = t.substring(pos + 1);
     
    -            if (opt.length() == 1)
    +          //check if equal is in argument (-option"test=arg")
    +          // -L=V
    +          // if (opt.length()>1 && !options.hasOption(opt))
    +          {
    +            //Search for long option and use correct option/argument if found
    +            String newOpt=getLongPrefix(opt);
    +            if (newOpt!=null)
    +            {
    +              pos = newOpt.length();
    +              opt = t.substring(0, pos);
    +              value = t.substring(pos);
    +            }
    +            //check if equal is in argument (-o"test=arg") and use correct short option if found
    +            // -S=V
    +            else if (options.hasOption(opt.substring(0,1)) && !opt.substring(1,2).contains("="))
    +            {
    +              opt = t.substring(0, 1);
    +              value = t.substring(1);
    +            }
    +          }
    +
    +
    +          if (opt.length() == 1)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by jlm429 <gi...@git.apache.org>.
Github user jlm429 commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    my bad... I guess it makes sense to wait to merge the test until the bug is fixed.  


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by jlm429 <gi...@git.apache.org>.
Github user jlm429 commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    Just adding this diff from the code above if needed for future reference.  this pr can be closed - do we possibly need more committers for CLI?  It doesn't seem like anyone is paying attention to the 2 that are open... 
    
    @@ -540,10 +539,32 @@ else if (isJavaProperty(t))
                 String opt = t.substring(0, pos);
                 String value = t.substring(pos + 1);
     
    -            if (opt.length() == 1)
    +          //check if equal is in argument (-option"test=arg")
    +          // -L=V
    +          // if (opt.length()>1 && !options.hasOption(opt))
    +          {
    +            //Search for long option and use correct option/argument if found
    +            String newOpt=getLongPrefix(opt);
    +            if (newOpt!=null)
    +            {
    +              pos = newOpt.length();
    +              opt = t.substring(0, pos);
    +              value = t.substring(pos);
    +            }
    +            //check if equal is in argument (-o"test=arg") and use correct short option if found
    +            // -S=V
    +            else if (options.hasOption(opt.substring(0,1)) && !opt.substring(1,2).contains("="))
    +            {
    +              opt = t.substring(0, 1);
    +              value = t.substring(1);
    +            }
    +          }
    +
    +
    +          if (opt.length() == 1)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by chtompki <gi...@git.apache.org>.
Github user chtompki commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    I see you got it sorted. I'll give this a look in the morning. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by jlm429 <gi...@git.apache.org>.
Github user jlm429 commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    my bad... I guess it makes sense to wait to merge the test until the bug is fixed.  


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    
    [![Coverage Status](https://:/builds/12017835/badge)](https://:/builds/12017835)
    
    Coverage remained the same at 96.244% when pulling **a2b142847c452f27462575cce3534ef534796b69 on jlm429:master** into **c246bd419ee0efccd9a96f9d33486617d5d38a56 on apache:master**.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by jlm429 <gi...@git.apache.org>.
Github user jlm429 commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    Yep, that works for me.  


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by chtompki <gi...@git.apache.org>.
Github user chtompki commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    My impression base on my reading of the [CLI-260](https://issues.apache.org/jira/browse/CLI-260) is that from this code:
    
    ```java
      private DefaultParser parser;
      private Options options;
    
      @Before
      public void setUp()
      {
        parser = new DefaultParser();
        options = new Options()
          .addOption("a", "enable-a", false, "turn [a] on or off")
          .addOption("b", "bfile", true, "set the value of [b]")
          .addOption("c", "copt", false, "turn [c] on or off")
          .addOption("k", "kopt", true, "set value of k");
      }
    
      @Test
      public void testProblem() throws Exception
      {
        String[] args = new String[] {"-k'option=value'"};
        CommandLine cl = parser.parse(options, args);
    
        String temp = "temp";
      }
    ```
    
    we get this exception:
    
    ```
    org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -k'option=value'
    
    	at org.apache.commons.cli.DefaultParser.handleUnknownToken(DefaultParser.java:359)
    	at org.apache.commons.cli.DefaultParser.handleLongOptionWithEqual(DefaultParser.java:439)
    	at org.apache.commons.cli.DefaultParser.handleShortAndLongOption(DefaultParser.java:568)
    	at org.apache.commons.cli.DefaultParser.handleToken(DefaultParser.java:242)
    	at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:119)
    	at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:75)
    	at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:59)
    	at org.apache.commons.cli.bug.BugCLI260Test.testProblem(BugCLI260Test.java:71)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:547)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    ```
    
    @jlm429, @britter - thoughts?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by jlm429 <gi...@git.apache.org>.
Github user jlm429 commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    fwiw - this is what I had to fix ... probably better off not digging around in the default parser though if not needed :0
    
        private void handleShortAndLongOption(String token) throws ParseException
        {
            String t = Util.stripLeadingHyphens(token);
    
            int pos = t.indexOf('=');
    
            if (t.length() == 1)
            {
                // -S
                if (options.hasShortOption(t))
                {
                    handleOption(options.getOption(t));
                }
                else
                {
                    handleUnknownToken(token);
                }
            }
            else if (pos == -1)
            {
                // no equal sign found (-xxx)
                if (options.hasShortOption(t))
                {
                    handleOption(options.getOption(t));
                }
                else if (!options.getMatchingOptions(t).isEmpty())
                {
                    // -L or -l
                    handleLongOptionWithoutEqual(token);
                }
                else
                {
                    // look for a long prefix (-Xmx512m)
                    String opt = getLongPrefix(t);
    
                    if (opt != null && options.getOption(opt).acceptsArg())
                    {
                        handleOption(options.getOption(opt));
                        currentOption.addValueForProcessing(t.substring(opt.length()));
                        currentOption = null;
                    }
                    else if (isJavaProperty(t))
                    {
                        // -SV1 (-Dflag)
                        handleOption(options.getOption(t.substring(0, 1)));
                        currentOption.addValueForProcessing(t.substring(1));
                        currentOption = null;
                    }
                    else
                    {
                        // -S1S2S3 or -S1S2V
                        handleConcatenatedOptions(token);
                    }
                }
            }
            else
            {
                // equal sign found (-xxx=yyy)
                String opt = t.substring(0, pos);
                String value = t.substring(pos + 1);
    
                //check if equal is in argument (-option"test=arg")
                // -L=V
                if (opt.length()>1 && !options.hasOption(opt))
                {
                    //Search for long option and use correct option/argument if found
                    String newOpt=getLongPrefix(opt);
                    if (newOpt!=null)
                    {
                      pos = newOpt.length();
                      opt = t.substring(0, pos);
                      value = t.substring(pos);
                    }
                    //check if equal is in argument (-o"test=arg") and use correct short option if found
                    // -S=V
                    else if (options.hasOption(opt.substring(0,1)) && !opt.substring(1,2).contains("="))
                    {
                     opt = t.substring(0, 1);
                     value = t.substring(1);
                   }
                }
    
    
    
    
                if (opt.length() == 1)
                {
                    // -S=V
                    Option option = options.getOption(opt);
                    if (option != null && option.acceptsArg())
                    {
                        handleOption(option);
                        currentOption.addValueForProcessing(value);
                        currentOption = null;
                    }
                    else
                    {
                        handleUnknownToken(token);
                    }
                }
                else if (isJavaProperty(opt))
                {
                    // -SV1=V2 (-Dkey=value)
                    handleOption(options.getOption(opt.substring(0, 1)));
                    currentOption.addValueForProcessing(opt.substring(1));
                    currentOption.addValueForProcessing(value);
                    currentOption = null;
                }
                else
                {
                    // -L=V or -l=V
                    handleLongOptionWithEqual(token);
                }
            }
        }



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli pull request #14: Added BugCLI260 JUnit Test

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/commons-cli/pull/14


---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by chtompki <gi...@git.apache.org>.
Github user chtompki commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    I see you got it sorted. I'll give this a look in the morning. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-cli issue #14: Added BugCLI260 JUnit Test

Posted by chtompki <gi...@git.apache.org>.
Github user chtompki commented on the issue:

    https://github.com/apache/commons-cli/pull/14
  
    No worries at all. While here, what are your thoughts about that scenario? To me it seems odd if you concatenated a flag with the value it represents. Clearly Java delimits arguments passed into a "public static void main" with spaces, so in my mind the ticket could be marked as won't fix and you're tests are still quite valid. 
    
    Curious what your thoughts are. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org