Imported Upstream version 17.0.2
[platform/upstream/libzypp.git] / tools / zypp-cpeid.cc
1 #include <iostream>
2 #include <zypp/CpeId.h>
3 #include <zypp/Pathname.h>
4
5 using std::cout;
6 using std::endl;
7 using zypp::CpeId;
8 using zypp::Pathname;
9
10 int main( int argc, const char * argv[] )
11 {
12   if ( argc == 1 || argv[1] == std::string( "--help" ) || argv[1] == std::string( "-h" ) )
13   {
14     cout <<
15     "Usage: " << Pathname::basename( argv[0] ) << " [CPEID]...\n"
16     "Check and print all supplied CPEIDs as FS, URI and WFN.\n"
17     "Afterwards compare them pairwise. \n"
18     "\n"
19     "      (wfn:[part=\"a\",vendor=\"openSUSE\",product=\"libzypp\",version=\"14\\.17\\.3\"])\n"
20     "  URI: cpe:/a:openSUSE:libzypp:14.17.3\n"
21     "  FS:  cpe:2.3:a:openSUSE:libzypp:14.17.3:*:*:*:*:*:*:*\n"
22     "\n";
23
24     return 0;
25   }
26   --argc, ++argv;
27
28
29   std::vector<CpeId> args;
30   args.reserve( argc );
31
32   for ( ; argc; --argc, ++argv )
33   {
34     try {
35       CpeId cpe( argv[0] );
36       cout << '[' << args.size() << "]-----------------------------------------------------------------------------" << endl;
37       cout << "arg: " << argv[0] << endl;
38       cout << "    (" << cpe.asWfn() << ')' << endl;
39       cout << "URI: " << cpe.asUri() << endl;
40       cout << "FS:  " << cpe<< endl;
41       args.push_back( cpe );
42     }
43     catch ( const std::invalid_argument & exp )
44     {
45       cout << "--------------------------------------------------------------------------------" << endl;
46       cout << "arg: " << argv[0] << endl;
47       cout << "ERR: " << exp.what() << endl;
48     }
49   }
50
51   cout << "--------------------------------------------------------------------------------" << endl;
52   unsigned lhsidx = 0;
53   for ( const auto & lhs : args )
54   {
55     unsigned rhsidx = 0;
56     for ( const auto & rhs : args )
57     {
58       cout << "[" << lhsidx << "]  " << lhs << endl;
59       cout << "[" << rhsidx << "]  " << rhs << endl;
60       cout << " ==> " << compare( lhs, rhs ) << endl;
61       ++rhsidx;
62     }
63     ++lhsidx;
64   }
65   return 0;
66 }