commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CLI-274) Option parser type EXISTING_FILE_VALUE not check file existing
Date Mon, 12 Jun 2017 18:40:01 GMT

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

ASF GitHub Bot commented on CLI-274:
------------------------------------

Github user britter commented on a diff in the pull request:

    https://github.com/apache/commons-cli/pull/12#discussion_r121493262
  
    --- Diff: src/test/java/org/apache/commons/cli/PatternOptionBuilderTest.java ---
    @@ -159,13 +161,12 @@ public void testURLPattern() throws Exception
         @Test
         public void testExistingFilePattern() throws Exception
         {
    -        final Options options = PatternOptionBuilder.parsePattern("f<");
    +        final Options options = PatternOptionBuilder.parsePattern("f<g<");
             final CommandLineParser parser = new PosixParser();
    -        final CommandLine line = parser.parse(options, new String[] { "-f", "test.properties"
});
    -
    -        assertEquals("f value", new File("test.properties"), line.getOptionObject("f"));
    -
    -        // todo test if an error is returned if the file doesn't exists (when it's implemented)
    +        final CommandLine line = parser.parse(options, new String[] { "-f", "test.properties",
"-g", "/dev/null" });
    +        
    +        assertNotNull("option g not parsed, or not FileInputStream", (FileInputStream)
line.getOptionObject("g"));
    +        assertNull("option f parsed", (FileInputStream) line.getOptionObject("f"));
    --- End diff --
    
    > Yes, It is null because test.properties does not exist, or not readable. This can
be made clearer somehow.
    
    Maybe by calling it `non-existing.file`?
    
    > Another task is to find a cross-platform file which is exist (and not /dev/null).
    
    You could put add dummy file in `src/test/resources` and use that one.


> Option parser type EXISTING_FILE_VALUE not check file existing
> --------------------------------------------------------------
>
>                 Key: CLI-274
>                 URL: https://issues.apache.org/jira/browse/CLI-274
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Parser
>            Reporter: Béla Schaum
>            Priority: Minor
>
> When the user pass option type FileInputStream.class, I think the expected behavior for
the return value is the same type, which the user passed.
> Options options = new Options();
> options.addOption(Option.builder("f").hasArg().type(FileInputStream.class).build());
> CommandLine cline = new DefaultParser().parse(options, args);
> FileInputStream file = (FileInputStream) cline.getParsedOptionValue("f"); // it returns
"File" object, without check File exist.
> I attach a solution for it:
> https://github.com/schaumb/commons-cli/commit/abfcc8211f529ab75f3b3edd4a827e484109eb0b



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message