add option to output bare numbers for use in scripts

pull/141/head
bert hubert 2020-09-27 16:04:57 +02:00
parent 42c46f532f
commit 6a963b181c
1 changed files with 18 additions and 1 deletions

View File

@ -7,16 +7,21 @@ extern const char* g_gitHash;
using namespace std;
int main(int argc, char** argv)
try
{
string program("gndate");
CLI::App app(program);
string date;
int galwn{-1};
bool doProgOutput{false};
bool doGPSWN{false}, doGALWN{false}, doVERSION{false}, doUTC{false};
app.add_flag("--version", doVERSION, "show program version and copyright");
app.add_option("--date,-d", date, "yyyy-mm-dd hh:mm");
app.add_option("--date,-d", date, "yyyy-mm-dd hh:mm[:ss] hh:mm yyyymmdd hhmm");
app.add_option("--date-gal-wn", galwn, "Give data for this Galileo week number");
app.add_flag("--utc,-u", doUTC, "Interpret --date,-d as UTC");
app.add_flag("--gps-wn", doGPSWN, "Print GPS week number");
app.add_flag("--gal-wn", doGALWN, "Print GPS week number");
app.add_flag("--prog-output", doProgOutput, "Modulate some date formats for use as parameters to programs");
try {
app.parse(argc, argv);
} catch(const CLI::Error &e) {
@ -40,6 +45,15 @@ int main(int argc, char** argv)
int wn, tow;
if(galwn >= 0) {
time_t week=utcFromGST(galwn, 0);
if(doProgOutput)
cout<<influxTime(week) << endl;
else
cout<<humanTime(week)<< " - " << humanTime(week+7*86400) << endl;
return 0;
}
if(doGPSWN) {
getGPSDateFromUTC(now, wn, tow);
cout<<wn<<endl;
@ -55,3 +69,6 @@ int main(int argc, char** argv)
cout<<"Galileo Week Number: "<< wn << ", tow " << tow << endl;
}
}
catch(exception& e) {
cerr<<"Error: "<<e.what()<<endl;
}