Skip to content

Commit a7d14bb

Browse files
committed
Changed download behavior to better follow UNIX logic. From now on, download defaults to printing to stdout, instead of writing to a default data.dsv file. Removed -s option, since it is no longer neccesary. Updated help text according to these changes. Updated logger redirections.
1 parent 0fa13bb commit a7d14bb

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/main.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,19 @@ int main(int argc, char *argv[]){
8080
return 1;
8181
} else {
8282
if (strcmp(argv[1],"download") == 0){ //if the user wants to download the data
83-
bool standard = false;
83+
bool standard = true;
8484
bool header = true;
8585
bool timestamps = true;
8686
string output = "data.dsv";
8787
for (int i = 2; i < argc; i++){ //interpreting the arguments
8888
if (strcmp(argv[i],"-s") == 0){
89-
standard = true;
89+
cerr << "Deprecated option. The program now defaults to stdout unless -o is specified. No data was downloaded." << endl;
90+
return 5;
9091
} else if (strcmp(argv[i],"-o") == 0){
9192
if (argc > i+1){
9293
if (argv[i+1][0] != '-'){
9394
output = argv[++i];
95+
standard = false;
9496
} else {
9597
cerr << "Error: missing or bad argument for option '-o' (filename cannot start with '-')" << endl;
9698
return 2;
@@ -109,19 +111,23 @@ int main(int argc, char *argv[]){
109111
}
110112
}
111113
voltcraft vdl191v(vid,pid); //if everything was alright
112-
confdata livec;
114+
confdata livec; //`live` config on device
113115
unsigned short int *data;
114116
try {
115117
vdl191v.download(&data,livec); //try to download the data from the device
116118
} catch(string ex){
117119
cerr << ex << endl;
118120
return 3;
119121
}
120-
logger lg(livec,data,timestamps,header,standard);
121-
ofstream f;
122-
f.open(output);
123-
f << lg; //save the downloaded data to file
124-
f.close();
122+
logger lg(livec,data,timestamps,header);
123+
if (standard){
124+
cout << lg;
125+
} else {
126+
ofstream f;
127+
f.open(output);
128+
f << lg; //save the downloaded data to file
129+
f.close();
130+
}
125131
return 0;
126132
} else if (strcmp(argv[1],"setup") == 0){ //setup
127133
if (argc == 2) {
@@ -212,8 +218,7 @@ int main(int argc, char *argv[]){
212218
"Note: This will stop the measurement.\n" +
213219
lend +
214220
"Options:\n" +
215-
" -s Print output to stdout as well\n" +
216-
" -o Specify output file. Default: data.dsv\n" +
221+
" -o Redirect output to the specified file instead.\n" +
217222
" --no-header Disables header in output file (first line)\n" +
218223
" --no-timestamps Disables the time row completely";
219224
cout << dhelp << endl;

0 commit comments

Comments
 (0)