Imported Upstream version 17.23.7
[platform/upstream/libzypp.git] / tools / DiskUsageCounter.cc
1 #define INCLUDE_TESTSETUP_WITHOUT_BOOST
2 #include "../tests/lib/TestSetup.h"
3 #undef  INCLUDE_TESTSETUP_WITHOUT_BOOST
4 #include "argparse.h"
5
6 #include <iostream>
7 #include <zypp/DiskUsageCounter.h>
8
9 using std::cout;
10 using std::cerr;
11 using std::endl;
12
13 static std::string appname { "NO_NAME" };
14
15 int errexit( const std::string & msg_r = std::string(), int exit_r = 100 )
16 {
17   if ( ! msg_r.empty() )
18     cerr << endl << appname << ": ERR: " << msg_r << endl << endl;
19   return exit_r;
20 }
21
22 int usage( const argparse::Options & options_r, int return_r = 0 )
23 {
24   cerr << "USAGE: " << appname << " [OPTION]... [ARGS]..." << endl;
25   cerr << "    Print default mountpoint set for disk usage computation." << endl;
26   cerr << options_r << endl;
27   return return_r;
28 }
29
30 int main( int argc, char * argv[] )
31 {
32   appname = Pathname::basename( argv[0] );
33
34   std::string sysRoot { "/" };
35
36   argparse::Options options;
37   options.add()
38     ( "help,h", "Print help and exit." )
39     ( "root",   "Use the system located below ROOTDIR.", argparse::Option::Arg::required )
40     ;
41   auto result = options.parse( argc, argv );
42
43   if ( result.count( "help" ) )
44     return usage( options );
45
46   if ( result.count( "root" ) )
47     sysRoot = result["root"].arg();
48
49   // go...
50   cout << "DiskUsageCounter: relevant mount points detected below '" << sysRoot << "':" << endl;
51   cout << DiskUsageCounter::detectMountPoints( sysRoot ) << endl;
52
53   return 0;
54 }