class GlobTransferItemFinder implements TransferItemFinder {

    @Override
    public Set<TransferItem> find(final CommandLine input, final TerminalAction action, final Path remote) throws AccessDeniedException {
        if(input.getOptionValues(action.name()).length == 2) {
            final String path = input.getOptionValues(action.name())[1];
            // This only applies to a shell where the glob is not already expanded into multiple arguments
            if(StringUtils.containsAny(path, '*', '?')) {
                final Local directory = LocalFactory.get(FilenameUtils.getFullPath(path));
                if(directory.isDirectory()) {
                    final PathMatcher matcher = FileSystems.getDefault().getPathMatcher(String.format("glob:%s", PathNormalizer.name(path)));
                    final Set<TransferItem> items = new HashSet<TransferItem>();
                    for(Local file : directory.list(new NullFilter<String>() {
                        @Override
                        public boolean accept(final String file) {
                            try {
                                return matcher.matches(Paths.get(file));
                            }
                            catch(InvalidPathException e) {
                                log.warn(String.format("Failure obtaining path for file %s", file));
                            }
                            return false;
                        }
                    })) {
                        items.add(new TransferItem(new Path(remote, file.getName(), EnumSet.of(Path.Type.file)), file));
                    }
                    return items;
                }
            }
        }
        return new SingleTransferItemFinder().find(input, action, remote);
    }

}