Skip to content

Commit fb82546

Browse files
committed
Improve todo get
1 parent 910ce0a commit fb82546

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

todo.cpp

+23-8
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ int main(int argc, char *argv[]) {
181181
action = 4;
182182
else
183183
cout << "Erreur : Priorité non interprétable" << endl;
184-
}else if ( !strcmp( argv[1], "get") ) {
185-
if( argc > 2 && argv[2][0] >= '0' && argv[2][0] <= '9' )
186-
action = 5,color = false;
184+
}else if ( !strcmp( argv[1], "get") || !strcmp(argv[1], "g") ) {
185+
if( argc > 2 )
186+
action = 5;
187187
else
188-
cout << "Erreur : Priorité non interprétable" << endl;
188+
cout << "Erreur : Besoin d'un sélecteur" << endl;
189189
}else if ( !strcmp( argv[1], "checked") ) {
190190
action = 6;
191191
}else if ( !strcmp( argv[1], "clean") || !strcmp( argv[1], "clear")
@@ -262,11 +262,26 @@ int main(int argc, char *argv[]) {
262262
modifyTODO( listTodo, argc-3, argv+3, [priority](todo& it) { it.priorite = priority; });
263263
}
264264
break;
265-
case 5: // s
266-
for (auto it = begin(listTodo); it != end(listTodo); ++it)
267-
if( it->priorite == atoi(argv[2]) )
268-
cout << *it;
265+
case 5: // get
266+
{
267+
char* res = NULL;
268+
int priorite = strtol(argv[2], &res, 0);
269+
if( res != argv[2] && *res == '\0' ) {
270+
for (auto it = begin(listTodo); it != end(listTodo); ++it)
271+
if( it->priorite == priorite )
272+
cout << *it;
273+
} else {
274+
for (auto it = begin(listTodo); it != end(listTodo); ++it) {
275+
for( int j = 2 ; j < argc ; j++ )
276+
if( it->str.find(argv[j]) != string::npos) {
277+
cout << *it;
278+
break;
279+
}
280+
}
281+
}
282+
269283
return 0;
284+
}
270285
case 6: // Checked
271286
for (auto it = begin(listTodo); it != end(listTodo); ++it)
272287
if( it->etat )

0 commit comments

Comments
 (0)