2016-09-21 21:57:27 -07:00
# include "vcpkg_Commands.h"
# include "vcpkg_System.h"
# include "vcpkg.h"
# include <iostream>
# include <iomanip>
namespace fs = std : : tr2 : : sys ;
namespace vcpkg
{
2016-09-21 22:47:36 -07:00
template < class Pred >
static void do_print ( const vcpkg_paths & paths , Pred predicate )
2016-09-21 21:57:27 -07:00
{
2016-09-21 22:14:02 -07:00
for ( auto it = fs : : directory_iterator ( paths . ports ) ; it ! = fs : : directory_iterator ( ) ; + + it )
2016-09-21 21:57:27 -07:00
{
2016-09-21 22:14:02 -07:00
const fs : : path & path = it - > path ( ) ;
2016-09-21 21:57:27 -07:00
try
{
auto pghs = get_paragraphs ( path / " CONTROL " ) ;
if ( pghs . empty ( ) )
continue ;
auto srcpgh = SourceParagraph ( pghs [ 0 ] ) ;
2016-09-21 22:47:36 -07:00
if ( predicate ( srcpgh . name ) )
{
std : : cout < < std : : left
< < std : : setw ( 20 ) < < srcpgh . name < < ' '
< < std : : setw ( 16 ) < < srcpgh . version < < ' '
< < shorten_description ( srcpgh . description ) < < ' \n ' ;
}
2016-09-21 21:57:27 -07:00
}
catch ( std : : runtime_error const & )
{
}
}
2016-09-21 22:47:36 -07:00
}
void search_command ( const vcpkg_cmd_arguments & args , const vcpkg_paths & paths )
{
2016-09-30 11:24:04 -07:00
static const std : : string example = Strings : : format ( " The argument should be a substring to search for, or no argument to display all libraries. \n %s " , create_example_string ( " search png " ) ) ;
args . check_max_arg_count ( 1 , example . c_str ( ) ) ;
2016-09-21 22:47:36 -07:00
if ( args . command_arguments . size ( ) = = 0 )
{
2016-11-07 13:43:36 -08:00
do_print ( paths , [ ] ( const std : : string & ) - > bool
2016-09-21 22:47:36 -07:00
{
return true ;
} ) ;
exit ( EXIT_SUCCESS ) ;
}
// At this point there is 1 argument
2016-11-06 20:12:21 -08:00
do_print ( paths , [ & ] ( const std : : string & port_name ) - > bool
2016-09-21 22:47:36 -07:00
{
2016-10-04 15:23:44 -07:00
return Strings : : case_insensitive_ascii_find ( port_name , args . command_arguments [ 0 ] ) ! = port_name . end ( ) ;
2016-09-21 22:47:36 -07:00
} ) ;
2016-09-21 21:57:27 -07:00
System : : println ( " \n If your library is not listed, please open an issue at: \n "
" https://github.com/Microsoft/vcpkg/issues " ) ;
exit ( EXIT_SUCCESS ) ;
}
}