Skip to content

Commit a6cdb59

Browse files
committed
reworked usage and -h behaviour
1 parent efa6caa commit a6cdb59

6 files changed

Lines changed: 28 additions & 5 deletions

File tree

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The following binaries are created:
1717
bin/seqgen Generate a random string
1818
bin/shuffler Shuffle a string or sequences inside a fasta file
1919

20-
Run these without any arguments or with the -h flag to see usage.
20+
Run these with the -h flag to see usage.
2121

2222

2323
countfa

src/countfa.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ int main(int argc, char **argv) {
128128
seqfile.open(optarg);
129129
if (seqfile.bad()) {
130130
cerr << "Error: file not found" << endl;
131+
cerr << "Run countfa -h to see usage." << endl;
131132
exit(EXIT_FAILURE);
132133
}
133134
has_file = true;
@@ -140,7 +141,8 @@ int main(int argc, char **argv) {
140141

141142
if (!has_file) {
142143
if (isatty(STDIN_FILENO)) {
143-
usage();
144+
cerr << "Error: missing input" << endl;
145+
cerr << "Run countfa -h to see usage." << endl;
144146
exit(EXIT_FAILURE);
145147
}
146148
do_countfa(cin);

src/countlets.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ int main(int argc, char **argv) {
100100
seqfile.open(optarg);
101101
if (seqfile.bad()) {
102102
cerr << "Error: file not found" << endl;
103+
cerr << "Run countlets -h to see usage." << endl;
103104
exit(EXIT_FAILURE);
104105
}
105106
has_file = true;
@@ -117,6 +118,7 @@ int main(int argc, char **argv) {
117118
outfile.open(optarg);
118119
if (outfile.bad()) {
119120
cerr << "Error: could not create outfile" << endl;
121+
cerr << "Run countlets -h to see usage." << endl;
120122
exit(EXIT_FAILURE);
121123
}
122124
has_out = true;
@@ -134,12 +136,14 @@ int main(int argc, char **argv) {
134136

135137
if (k < 1) {
136138
cerr << "Error: k must be greater than 0" << endl;
139+
cerr << "Run countlets -h to see usage." << endl;
137140
exit(EXIT_FAILURE);
138141
}
139142

140143
if (!has_file) {
141144
if (isatty(STDIN_FILENO)) {
142-
usage();
145+
cerr << "Error: missing input" << endl;
146+
cerr << "Run countlets -h to see usage." << endl;
143147
exit(EXIT_FAILURE);
144148
}
145149
}
@@ -180,6 +184,7 @@ int main(int argc, char **argv) {
180184

181185
if (alph.length() < 1) {
182186
cerr << "Error: could not parse -a option" << endl;
187+
cerr << "Run countlets -h to see usage." << endl;
183188
exit(EXIT_FAILURE);
184189
}
185190

src/countwin.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ int main(int argc, char **argv) {
102102
infile.open(optarg);
103103
if (infile.bad()) {
104104
cerr << "Error: file not found" << endl;
105+
cerr << "Run countwin -h to see usage." << endl;
105106
exit(EXIT_FAILURE);
106107
}
107108
has_file = true;
@@ -112,6 +113,7 @@ int main(int argc, char **argv) {
112113
outfile.open(optarg);
113114
if (outfile.bad()) {
114115
cerr << "Error: could not create outfile" << endl;
116+
cerr << "Run countwin -h to see usage." << endl;
115117
exit(EXIT_FAILURE);
116118
}
117119
has_out = true;
@@ -150,12 +152,14 @@ int main(int argc, char **argv) {
150152

151153
if (k < 1) {
152154
cerr << "Error: k must be greater than 0" << endl;
155+
cerr << "Run countwin -h to see usage." << endl;
153156
exit(EXIT_FAILURE);
154157
}
155158

156159
if (!has_file) {
157160
if (isatty(STDIN_FILENO)) {
158161
cerr << "Error: missing input" << endl;
162+
cerr << "Run countwin -h to see usage." << endl;
159163
exit(EXIT_FAILURE);
160164
}
161165
}
@@ -170,6 +174,7 @@ int main(int argc, char **argv) {
170174
} else {
171175
if (window < k) {
172176
cerr << "Error: window size must be equal to or greater than k" << endl;
177+
cerr << "Run countwin -h to see usage." << endl;
173178
exit(EXIT_FAILURE);
174179
}
175180
}
@@ -178,6 +183,7 @@ int main(int argc, char **argv) {
178183

179184
if (step < 1 || step > window) {
180185
cerr << "Error: step size must be between 1 and window size" << endl;
186+
cerr << "Run countwin -h to see usage." << endl;
181187
exit(EXIT_FAILURE);
182188
}
183189

@@ -204,6 +210,7 @@ int main(int argc, char **argv) {
204210
STOP = START + seq.length() - 1;
205211
if (seq.length() < k) {
206212
cerr << "Error: sequence cannot be smaller than k" << endl;
213+
cerr << "Run countwin -h to see usage." << endl;
207214
exit(EXIT_FAILURE);
208215
}
209216
counts = count_klets(vector<char>(seq.begin(), seq.end()), klets, lets_uniq, k, alphlen);

src/seqgen.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ int main(int argc, char **argv) {
6060
size_t last, next;
6161

6262
if (argc == 1) {
63-
usage();
63+
cerr << "Error: missing alphabet and sequence length" << endl;
64+
cerr << "Run seqgen -h to see usage." << endl;
6465
return 0;
6566
}
6667

@@ -70,6 +71,7 @@ int main(int argc, char **argv) {
7071
outfile.open(optarg);
7172
if (outfile.bad()) {
7273
cerr << "Error: could not create outfile" << endl;
74+
cerr << "Run seqgen -h to see usage." << endl;
7375
exit(EXIT_FAILURE);
7476
}
7577
has_out = true;
@@ -95,6 +97,7 @@ int main(int argc, char **argv) {
9597

9698
if (seqlen < 1) {
9799
cerr << "Error: please input a desired sequence length above 0" << endl;;
100+
cerr << "Run seqgen -h to see usage." << endl;
98101
exit(EXIT_FAILURE);
99102
}
100103

@@ -113,6 +116,7 @@ int main(int argc, char **argv) {
113116

114117
if (alphlen < 1) {
115118
cerr << "Error: could not parse sequence alphabet" << endl;
119+
cerr << "Run seqgen -h to see usage." << endl;
116120
exit(EXIT_FAILURE);
117121
}
118122

src/shuffler.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ int main(int argc, char **argv) {
210210
seqfile.open(optarg);
211211
if (seqfile.bad()) {
212212
cerr << "Error: file not found" << endl;
213+
cerr << "Run shuffler -h to see usage." << endl;
213214
exit(EXIT_FAILURE);
214215
}
215216
has_file = true;
@@ -226,6 +227,7 @@ int main(int argc, char **argv) {
226227
outfile.open(optarg);
227228
if (outfile.bad()) {
228229
cerr << "Error: could not create outfile" << endl;
230+
cerr << "Run shuffler -h to see usage." << endl;
229231
exit(EXIT_FAILURE);
230232
}
231233
has_out = true;
@@ -254,17 +256,20 @@ int main(int argc, char **argv) {
254256
}
255257

256258
if (!has_file && isatty(STDIN_FILENO)) {
257-
usage();
259+
cerr << "Error: missing input" << endl;
260+
cerr << "Run shuffler -h to see usage." << endl;
258261
exit(EXIT_FAILURE);
259262
}
260263

261264
if (k < 1) {
262265
cerr << "Error: k must be greater than 0" << endl;
266+
cerr << "Run shuffler -h to see usage." << endl;
263267
exit(EXIT_FAILURE);
264268
}
265269

266270
if (use_linear && use_markov) {
267271
cerr << "Error: only use one of -l and -m flags" << endl;
272+
cerr << "Run shuffler -h to see usage." << endl;
268273
exit(EXIT_FAILURE);
269274
}
270275

0 commit comments

Comments
 (0)