1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 21:57:34 +00:00

Userland+Terminal: Port to new CArgsParser API

While at it, also add some niceties and fix some things.
This commit is contained in:
Sergey Bugaev 2020-01-27 20:25:36 +03:00 committed by Andreas Kling
parent 9276582535
commit f983dfe319
22 changed files with 392 additions and 653 deletions

View file

@ -24,8 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <LibCore/CArgsParser.h>
#include <alloca.h>
#include <getopt.h>
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
@ -59,28 +59,13 @@ int main(int argc, char** argv)
perror("pledge");
return 1;
}
static const char* valid_option_characters = "ugGn";
int opt;
while ((opt = getopt(argc, argv, valid_option_characters)) != -1) {
switch (opt) {
case 'u':
flag_print_uid = true;
break;
case 'g':
flag_print_gid = true;
break;
case 'G':
flag_print_gid_all = true;
break;
case 'n':
flag_print_name = true;
break;
default:
fprintf(stderr, "usage: id [-%s]\n", valid_option_characters);
return 1;
}
}
CArgsParser args_parser;
args_parser.add_option(flag_print_uid, "Print UID", nullptr, 'u');
args_parser.add_option(flag_print_gid, "Print GID", nullptr, 'g');
args_parser.add_option(flag_print_gid_all, "Print all GIDs", nullptr, 'G');
args_parser.add_option(flag_print_name, "Print name", nullptr, 'n');
args_parser.parse(argc, argv);
if (flag_print_name && !(flag_print_uid || flag_print_gid || flag_print_gid_all)) {
fprintf(stderr, "cannot print only names or real IDs in default format\n");