Commit 8192d064 authored by Marc Betoule's avatar Marc Betoule
Browse files

improve the help message

parent 94cc63b8
......@@ -58,8 +58,9 @@ int main(int argc ,const char** argv)
ArgType type[] = {FLAG, INT, INT, FLAG, STRING};
string usage[] = {"Inputs are alm FITS file.", "Number of iteration of anafast.", "Resolution of the output map.", "Pixel based analysis", "Pixel zone definition"};
char shortopt[] = "ainpz";
Args args = Args(5, longopt, shortopt, type, usage,"Perform needlet ILC.", "outfile l0 J zonefile1 lmax1 ... zonefileJ lmaxJ N infile1 coeff1 ... infileN coeffN \n -p outfile -z zonefile N infile1 coeff1 ... infileN coeffN ");
Args args = Args(5, longopt, shortopt, type, usage,"Compute ILC in needlet or pixel space.");
args.add_usage("", "ain", "outfile l0 J zonefile1 lmax1 ... zonefileJ lmaxJ N infile1 coeff1 ... infileN coeffN");
args.add_usage("pz", "" ," outfile N infile1 coeff1 ... infileN coeffN");
// parameter file
if ((argc == 2) && (argv[1][0]!='-'))
......
......@@ -19,7 +19,7 @@
#include <iostream>
#include <sstream>
#include <cstdlib>
Args::Args(int noptions, string * longoptions, char * shortoptions, ArgType * type, string * usage, string _purpose, string _fullusage){
Args::Args(int noptions, string * longoptions, char * shortoptions, ArgType * type, string * usage, string _purpose){
longOpts = new struct option [noptions+1];
shortOpts = "";
optionroles = "";
......@@ -36,7 +36,7 @@ Args::Args(int noptions, string * longoptions, char * shortoptions, ArgType * ty
longOpts[i] = o;
shortOpts += shortoptions[i];
shortOpts += ":";
optionroles += "\n--"+longoptions[i]+", -"+shortoptions[i]+ " <string>\t: " + usage[i];
optionroles += "\n --"+longoptions[i]+", -"+shortoptions[i]+ " <string>\t: " + usage[i];
}
break;
case FLOAT :
......@@ -46,7 +46,7 @@ Args::Args(int noptions, string * longoptions, char * shortoptions, ArgType * ty
longOpts[i] = o;
shortOpts += shortoptions[i];
shortOpts += ":";
optionroles += "\n--"+longoptions[i]+", -"+shortoptions[i]+ " <float>\t: " + usage[i];
optionroles += "\n --"+longoptions[i]+", -"+shortoptions[i]+ " <float>\t: " + usage[i];
}
break;
case FLAG :
......@@ -55,7 +55,7 @@ Args::Args(int noptions, string * longoptions, char * shortoptions, ArgType * ty
struct option o = {longoptions[i].c_str(), no_argument, NULL, shortoptions[i]};
longOpts[i] = o;
shortOpts += shortoptions[i];
optionroles += "\n--"+longoptions[i]+", -"+shortoptions[i]+ "\t: " + usage[i];
optionroles += "\n --"+longoptions[i]+", -"+shortoptions[i]+ "\t: " + usage[i];
}
break;
case INT :
......@@ -65,39 +65,80 @@ Args::Args(int noptions, string * longoptions, char * shortoptions, ArgType * ty
longOpts[i] = o;
shortOpts += shortoptions[i];
shortOpts += ":";
optionroles += "\n--"+longoptions[i]+", -"+shortoptions[i]+ " <int>\t: " + usage[i];
optionroles += "\n --"+longoptions[i]+", -"+shortoptions[i]+ " <int>\t: " + usage[i];
}
break;
}
purpose = _purpose;
fullusage = _fullusage;
}
struct option o = {"help", no_argument, NULL, 'h'};
longOpts[noptions] = o;
shortOpts += "h";
}
void Args::add_usage(string compulsory_option_set, string optionnal_option_set, string positionnal_args){
string synopsis="";
if (flagvalues.size() > 0){
synopsis += " [-";
for (map<string, int>::iterator it = flagvalues.begin(); it != flagvalues.end(); it++)
synopsis += shortnames[it->first];
synopsis += "] ";
for (map<string, int>::iterator it = flagvalues.begin(); it != flagvalues.end(); it++){
string sn ="";
sn += shortnames[it->first];
if (compulsory_option_set.find(sn)!=string::npos){
synopsis += " -";
synopsis += shortnames[it->first];
synopsis += " ";
}
else if (optionnal_option_set.find(sn)!=string::npos){
synopsis += " [-";
synopsis += shortnames[it->first];
synopsis += "] ";
}
}
}
for (map<string, int>::iterator it = intvalues.begin(); it != intvalues.end(); it++){
synopsis += "[-";
synopsis += shortnames[it->first];
synopsis += " <int>] ";
string sn = "";
sn += shortnames[it->first];
if (compulsory_option_set.find(sn)!=string::npos){
synopsis += " -";
synopsis += shortnames[it->first];
synopsis += " <int> ";
}
else if (optionnal_option_set.find(sn)!=string::npos){
synopsis += " [-";
synopsis += shortnames[it->first];
synopsis += " <int>] ";
}
}
for (map<string, double>::iterator it = floatvalues.begin(); it != floatvalues.end(); it++){
synopsis += "[-";
synopsis += shortnames[it->first];
synopsis += " <float>] ";
string sn = "";
sn += shortnames[it->first];
if (compulsory_option_set.find(sn)!=string::npos){
synopsis += " -";
synopsis += shortnames[it->first];
synopsis += " <float> ";
}
else if (optionnal_option_set.find(sn)!=string::npos){
synopsis += " [-";
synopsis += shortnames[it->first];
synopsis += " <float>] ";
}
}
for (map<string, string>::iterator it = stringvalues.begin(); it != stringvalues.end(); it++){
synopsis += "[-";
synopsis += shortnames[it->first];
synopsis += " <string>] ";
string sn = "";
sn += shortnames[it->first];
if (compulsory_option_set.find(sn)!=string::npos){
synopsis += " -";
synopsis += shortnames[it->first];
synopsis += " <string> ";
}
else if (optionnal_option_set.find(sn)!=string::npos){
synopsis += " [-";
synopsis += shortnames[it->first];
synopsis += " <string>] ";
}
}
synopsis += fullusage+"\n";
synopsis += positionnal_args+"\n";
vec_synopsis.push_back(synopsis);
}
void Args::info(){
......@@ -116,8 +157,16 @@ void Args::info(){
}
void Args::printusage(){
cerr << synopsis << endl
<< purpose << endl
cerr << "Synopsis:\n"
<< "---------\n";
for (vector<string>::iterator it = vec_synopsis.begin(); it != vec_synopsis.end(); it++){
cerr << " " << name << *it << endl;
}
cerr << "Purpose:\n"
<< "--------\n";
cerr<< purpose << endl<<endl;
cerr << "Options:\n"
<< "--------"
<< optionroles << endl;
exit(EXIT_FAILURE);
......@@ -156,9 +205,9 @@ void Args::processarg(int val){
void Args::processargs(int argc, char **argv){
int opt = 0;
int longIndex = 0;
string name = argv[0];
synopsis = name.substr(name.find_last_of('/')+1) + synopsis;
synopsis = "Synopsis:\n" + synopsis;
name = argv[0];
name = name.substr(name.find_last_of('/')+1);
opterr = 0;
opt = getopt_long( argc, argv, shortOpts.c_str(), longOpts, &longIndex );
while( opt != -1 ) {
......@@ -183,7 +232,12 @@ bool Args::operator [](string key){
}
string Args::operator[](int i){
return posarg[i];
if (i < nposarg)
return posarg[i];
else{
cerr << "Missing positionnal argument: " << i << endl;
printusage();
}
}
void Args::def (int val,string key){
......
......@@ -19,6 +19,7 @@
#include <getopt.h>
#include <string>
#include <map>
#include <vector>
using namespace std;
......@@ -28,8 +29,10 @@ class Args
{
public:
// constructor
Args(int noptions, string * longoptions, char * shortoptions, ArgType * type, string * usage, string purpose="", string fullusage="");
Args(int noptions, string * longoptions, char * shortoptions, ArgType * type, string * usage, string purpose="");
void add_usage(string compulsory_option_set, string optionnal_option_set, string positionnal_args);
// various
void info();
void printusage();
......@@ -71,9 +74,10 @@ private:
string fullusage;
string shortOpts;
string optionroles;
string synopsis;
vector<string> vec_synopsis;
struct option * longOpts;
string name;
// options storage
map<string,int> intvalues;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment