Small opt in parsing args

switch from ifs to switch
This commit is contained in:
nikola 2024-06-20 02:07:25 +02:00
parent 3d1f223086
commit 31e9935511

View File

@ -41,42 +41,52 @@ Arg get_args(int argc, char **argv, char **label)
return Arg::Error;
}
if (!strcmp("-h", argv[1]))
{
print_args();
return Arg::Error;
}
if (!strcmp("-l", argv[1]))
return Arg::List;
if (!strcmp("-p", argv[1]))
return Arg::Print_all_p;
if (!strcmp("-c", argv[1]))
return Arg::Change;
if (argc < 3)
if (argv[1][0] != '-')
{
*label = argv[1];
return Arg::Get;
}
switch (argv[1][1])
{
case 'h':
print_args();
return Arg::Error;
case 'l':
return Arg::List;
case 'p':
return Arg::Print_all_p;
case 'c':
return Arg::Change;
}
if (argc != 3)
return Arg::Error;
*label = argv[2];
if (!strcmp("-g", argv[1]))
switch (argv[1][1])
{
case 'g':
return Arg::Generate;
if (!strcmp("-d", argv[1]))
case 'd':
return Arg::Delete;
if (!strcmp("-i", argv[1]))
case 'i':
return Arg::Input;
if (!strcmp("-s", argv[1]))
case 's':
return Arg::Show;
if (!strcmp("-u", argv[1]))
case 'u':
return Arg::Username;
if (!strcmp("-n", argv[1]))
case 'n':
return Arg::Name;
if (!strcmp("-f", argv[1]))
case 'f':
return Arg::File;
default:
return Arg::Error;
break;
}
return Arg::Error;
}