int main(int argc, char *argv[]) { try { po::options_description desc("v0.1,\nSupported options"); desc.add_options()( // "help,h", "produce help message")( // "version,v", "version information")( // "input,i", po::value<string>(), "specify input file")( // "output,o", po::value<string>(), "specify output file"); po::positional_options_description p; p.add("input", -1); po::variables_map vm; po::store(po::command_line_parser(argc, argv) // .options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("help")) { cout << desc << "\n"; return 1; } if (vm.count("version")) { cout << desc << "\n"; return 1; } bool error = false; if (vm.count("input")) { cout << "Input file was set to " << vm["input"].as<string>() << "." << endl; } else { error = true; cout << "Input file was not set, but this is required." << endl; } if (vm.count("output")) { cout << "Output file was set to " << vm["output"].as<string>() << "." << endl; } else { cout << "Output file was not set." << endl; } if (error) { cout << "Abort program. Use --help to get a list of the available options." << endl; return 1; } FileStorage storage; storage.SetFilter(boost::shared_ptr<FilterIsActive>(new FilterIsActive())); storage.Load(vm["input"].as<string>()); storage.Save(vm["output"].as<string>()); cout << "Saved the active articles from " << vm["input"].as<string>(); cout << " into " << vm["output"].as<string>() << ".\n"; } catch (exception& e) { cerr << "error: " << e.what() << endl; return 1; } catch (std::string const& e) { cerr << "error: " << e << endl; cout << "Current directory: " << fs::initial_path() << endl; return 1; } catch (...) { cerr << "Exception of unknown type!" << endl; } return 0; }