Implement -h flag and specific boss printing
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Thu, 7 Mar 2024 09:55:06 +0000 (10:55 +0100)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Thu, 7 Mar 2024 09:55:06 +0000 (10:55 +0100)
Also prepare a little for -l flag.

TODO
src/main.c

diff --git a/TODO b/TODO
index ab7ef36c154e70ca0d9de13d42dda9e109be27fd..ef2b64608188c0abb9da41adfc19375dd7be1118 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,5 +1,7 @@
 TODO
 give option -l the functionality described in help
-implement -h flag?
 colored output
 sort available bosses by level?
+
+DONE
+implement -h flag
index ff61748c09ba3e0fae57c6df3c16b6f6fe12ed70..b20b5433a23d55d7aa38a004dc0b14ab2a698675 100644 (file)
@@ -20,7 +20,9 @@ typedef enum e_basic_command
        basic_kill,
        basic_add,
        basic_list,
+       basic_loop,
        basic_remove,
+       basic_help,
 }      t_basic;
 
 typedef struct s_command
@@ -196,11 +198,24 @@ int       parse_input(t_command *command, int argc, char **argv)
        command->entry.name = NULL;
        if (argc == 1)
                return (0);
-       else if (argc == 2 && !ft_strcmp(argv[1], "-l"))
+       else if (argc == 2)
+       {
+               if (!ft_strcmp(argv[1], "-l"))
+                       command->basic = basic_loop;
+               else if (!ft_strcmp(argv[1], "-h"))
+                       command->basic = basic_help;
+               else
+                       command->entry.name = argv[1];
+               return (0);
+       }
+       else if (argc == 2)
+       {
+               command->entry.name = argv[1];
                return (0);
+       }
        else if (argc == 3)
        {
-               if (ft_strcmp(argv[1], "-l") && ft_strcmp(argv[1], "-k") && ft_strcmp(argv[1], "-r"))
+               if (ft_strcmp(argv[1], "-k") && ft_strcmp(argv[1], "-r"))
                        return (1);
                command->entry.name = argv[2];
                if (argv[1][1] == 'k')
@@ -247,6 +262,30 @@ int        find_name_ind(t_vec *database, const char *name, size_t *ind)
        return (1);
 }
 
+void   print_help(void)
+{
+       static const char       *helpstr = 
+               "Palboss is a simple tracker of cooldown of bosses in Palworld\n"
+               "Usage:\tpalboss [option option_arguments]\n"
+               "\tWithout options it lists all the bosses\n"
+               "Options:\n"
+               "\tboss\n"
+               "\t\tPrint the info about the boss\n"
+               "\t-h\n"
+               "\t\tPrint this help.\n"
+               "\t-l\n"
+               "\t\tPrint the list in a loop. End by using Q key.\n"
+               "\t-k boss\n"
+               "\t\tMark the boss as killed, setting the counter to 60 minutes.\n"
+               "\t-a boss level location\n"
+               "\t\tAdd a boss to the database. Long strings may break formatting.\n"
+               "\t-r boss\n"
+               "\t\tRemove a boss from the database.\n";
+
+       ft_printf("%s", helpstr);
+       return ;
+}
+
 void   carry_out_command(t_command *com, t_vec *database)
 {
        size_t  ind;
@@ -269,26 +308,8 @@ void       carry_out_command(t_command *com, t_vec *database)
                else
                        print_entry(ft_vec_access(database, ind));
        }
-       return ;
-}
-
-void   print_help(void)
-{
-       static const char       *helpstr = 
-               "Palboss is a simple tracker of cooldown of bosses in Palworld\n"
-               "Usage:\tpalboss [option option_arguments]\n"
-               "\tWithout options it lists all the bosses\n"
-               "Options:\n"
-               "\t-l\n"
-               "\t\tPrint the list in a loop. End by using Q key.\n"
-               "\t-k boss\n"
-               "\t\tMark the boss as killed, setting the counter to 60 minutes.\n"
-               "\t-a boss level location\n"
-               "\t\tAdd a boss to the database. Long strings may break formatting.\n"
-               "\t-r boss\n"
-               "\t\tRemove a boss from the database.\n";
-               
-       ft_printf("%s", helpstr);
+       else if (com->basic == basic_help)
+               print_help();
        return ;
 }