2626#include < algorithm>
2727#include < iostream>
2828#include < set>
29+ #include < sstream>
30+ #include < stdexcept>
2931#include < vector>
3032#include " boost/algorithm/string/predicate.hpp"
3133
3234#include " partition/ConfigStore.h"
3335#include " partition/Constants.h"
36+ #include " partition/Exceptions.h"
3437#include " partition/FileUtils.h"
3538
3639namespace fs = boost::filesystem;
@@ -75,8 +78,9 @@ ConfigStore parseCommandLine(po::options_description const& options, int argc, c
7578 po::store (po::parse_command_line (argc, const_cast <char **>(argv), all), vm);
7679 po::notify (vm);
7780 if ((vm.count (" help" ) != 0 ) && vm[" help" ].as <bool >()) {
78- std::cout << argv[0 ] << " [options]\n\n " << help << " \n " << all << std::endl;
79- std::exit (EXIT_SUCCESS);
81+ std::ostringstream oss;
82+ oss << argv[0 ] << " [options]\n\n " << help << " \n " << all << std::endl;
83+ throw ExitOnHelp (oss.str ());
8084 }
8185 // Parse configuration files, if any.
8286 if (vm.count (" config-file" ) != 0 ) {
@@ -218,8 +222,7 @@ void makeOutputDirectory(ConfigStore& config, bool mayExist) {
218222 outDir = config.get <std::string>(" out.dir" );
219223 }
220224 if (outDir.empty ()) {
221- std::cerr << " No output directory specified (use --out.dir)." << std::endl;
222- std::exit (EXIT_FAILURE);
225+ throw std::invalid_argument (" No output directory specified (use --out.dir)." );
223226 }
224227 outDir = fs::system_complete (outDir);
225228 if (outDir.filename () == " ." ) {
@@ -231,9 +234,8 @@ void makeOutputDirectory(ConfigStore& config, bool mayExist) {
231234 }
232235 config.set (" out.dir" , outDir.string ());
233236 if (fs::create_directories (outDir) == false && !mayExist) {
234- std::cerr << " The output directory --out.dir=" << outDir.string ()
235- << " already exists - please choose another." << std::endl;
236- std::exit (EXIT_FAILURE);
237+ throw std::runtime_error (" The output directory --out.dir=" + outDir.string () +
238+ " already exists - please choose another." );
237239 }
238240}
239241
@@ -244,8 +246,7 @@ void ensureOutputFieldExists(ConfigStore& config, std::string const& opt) {
244246 std::vector<std::string> columns;
245247 if (!config.has (" out.csv.field" )) {
246248 if (!config.has (" in.csv.field" )) {
247- std::cerr << " Input CSV column names not specified." << std::endl;
248- std::exit (EXIT_FAILURE);
249+ throw std::invalid_argument (" Input CSV column names not specified." );
249250 }
250251 columns = config.get <std::vector<std::string>>(" in.csv.field" );
251252 } else {
0 commit comments