Skip to content

Commit 104112f

Browse files
committed
Add option to use INI files for default values of batch command line options.
Will look for "InterSpec_batch.ini" in current directory, or you can specify path to INI file with the '--ini-file' command line options. Options specified on the command-line will take precedence over the values in the INI files.
1 parent 45457f7 commit 104112f

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/BatchCommandLine.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,15 @@ int run_batch_command( int argc, char **argv )
151151
bool use_existing_background_peaks;
152152
double peak_stat_threshold = 0.0, peak_hypothesis_threshold = 0.0;
153153
vector<std::string> input_files, report_templates, summary_report_templates;
154-
string exemplar_path, output_path, exemplar_samples, background_sub_file, background_samples, template_include_dir;
154+
string ini_file_path, exemplar_path, output_path, exemplar_samples, background_sub_file, background_samples, template_include_dir;
155155

156156
po::options_description peak_cl_desc("Allowed batch peak-fit, and activity-fit options", term_width, min_description_length);
157157
peak_cl_desc.add_options()
158158
("help,h", "Produce help message")
159+
("ini-file,i", po::value<std::string>(&ini_file_path)->default_value(""),
160+
"Path to INI file that can specify command line option defaults.\n"
161+
"(so you dont have to re-type things all the time)\n"
162+
"If not specified, will look for \"InterSpec_batch.ini\" in the current directory.")
159163
("exemplar", po::value<std::string>(&exemplar_path),
160164
"File containing exemplar peaks, that will try to be fitted in the input spectra."
161165
" Can be a N42-2012 file save from InterSpec that contains peaks, or a peaks CSV file"
@@ -305,6 +309,35 @@ int run_batch_command( int argc, char **argv )
305309
po::store( parsed_act_opts, cl_vm );
306310
}//if( batch_act_fit )
307311

312+
if( ini_file_path.empty() && SpecUtils::is_file("InterSpec_batch.ini") )
313+
ini_file_path = "InterSpec_batch.ini";
314+
315+
if( !ini_file_path.empty() )
316+
{
317+
try
318+
{
319+
ifstream input( ini_file_path.c_str() );
320+
if( !input )
321+
throw runtime_error( "Could not open config file '" + ini_file_path + "'" );
322+
323+
// It *looks* like the INI file will NOT overwrite the values from the command line
324+
po::store( po::parse_config_file( input, peak_cl_desc, true), cl_vm );
325+
input.seekg( 0 );
326+
po::store( po::parse_config_file( input, activity_cl_desc, true), cl_vm );
327+
input.seekg( 0 );
328+
if( batch_act_fit )
329+
{
330+
input.seekg( 0 );
331+
po::store( po::parse_config_file(input, activity_cl_desc, true), cl_vm );
332+
}
333+
334+
std::cout << "Using settings from '" << ini_file_path << "'" << endl;
335+
}catch( const std::exception & e )
336+
{
337+
std::cerr << "Error reading INI file: " << e.what() << " - skipping." << std::endl;
338+
}
339+
}//if( ini_file_path.empty() )
340+
308341
po::notify( cl_vm );
309342
}catch( std::exception &e )
310343
{

0 commit comments

Comments
 (0)