Boost logo

Boost :

Subject: [boost] [program_options] -d directory is falling into positional input-files 1_62_0
From: Roger Martin (roger_at_[hidden])
Date: 2016-10-14 14:22:50


Hi,

Pulled this from a larger application to isolate to the problem: -d
./tmp or -d "./tmp" doesn't go to directory string but is with the
positionals:

#include <stdlib.h>
#include <iostream>
#include <exception>
#include <string>
#include <cstring>
#include <memory>
#include <fstream>

#include "boost/program_options.hpp"

int main(int argc, char** argv) {
     try {
         boost::program_options::positional_options_description p;
         p.add("input-file", -1);
         std::string directory = "./";
         boost::program_options::options_description visible("Allowed
options");
         visible.add_options()
                 ("input-file",
boost::program_options::value<std::vector<std::string>>(), "input files
can be *.xml, *.pdb, *.mol2, *.mtz, *.cif, *.csv, and *.sdf. Csv and sdf
formats are for NMR calculations. csv lists the atoms for which the
shifts will be computed. 1st line containts the Header:
\"Chain\",\"Residue ID\",\"Sequence\",\"Atom Name\",\"Unbound
ppm\",\"Bound ppm\". Then atoms may be listed i.e
\"A\",\"MET\",231,\"CE\",10.30,10.50. sdf file contains the ligands for
a CSP calculation. ")
                 ("directory,d",
boost::program_options::value<std::string>(&directory)->implicit_value("./"),
"Directory for publishing output.")
                 ;
         boost::program_options::options_description all("Allowed options");
         all.add(visible);//.add(hidden);

         boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::command_line_parser(argc,
argv).options(all).positional(p).run(), vm);
         boost::program_options::notify(vm);
         std::vector<std::string> fileList = vm["input-file"].as <
std::vector < std::string >> ();
                 for (unsigned int fileListIndex = 0; fileListIndex <
fileList.size(); fileListIndex++) {
                     std::cout<<" "<<fileList[fileListIndex]<<"
"<<std::endl;
                 }

     } catch (std::exception& e) {
         std::cout << e.what() << std::endl;
     }
     return 0;
}

Built with g++ 4.9.0 on Linux frodo.quantumbioinc.com
2.6.32-573.7.1.el6.centos.plus.x86_64 #1 SMP Wed Sep 23 03:02:55 UTC
2015 x86_64 x86_64 x86_64 GNU/Linux

g++ -fPIE -std=c++11 -I${BOOST_HOME}/include
-Wl,--allow-multiple-definition -MT main.o -MMD -MP -O3 -c -o main.o
main.cpp
g++ -pie -Wl,--allow-multiple-definition -o main main.o
-L${BOOST_HOME}/lib -lboost_program_options -lc -lm -lpthread -lz
-lstdc++ -ldl -lrt

And run as

./main 2-aminoethanol.pdb -d ./tmp

which results in

  2-aminoethanol.pdb
  ./tmp

This code had been working with 1_57_0. Some change in the API I need
to adjust for?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk