66import argparse
77import platform
88from PyChecker .projects import libft , ft_commandements , other , fillit
9+ import sys
10+
11+
12+ def check_args_rules (parser , args ):
13+ """
14+ --verbose: Optionnal, no rules there.
15+ --no-gui: Enabled by default,
16+ --project: Required, Has a choice.
17+ --path: Required.
18+
19+ --no-author: Optionnal, no rules here expect 42commandements
20+ --no-forbidden-functions: Optionnal, can only be set when project=fdf|fillit|ft_ls|ft_p|ft_printf|gnl\libft|libftasm|minishell|pushswap
21+ --no-makefile: Optionnal, no rules here expect 42commandements
22+ --no-norm: Optionnal, no rules here expect 42commandements
23+ --no-static: Optionnal, can only be set when project=libft
24+ --no-extra: Optionnal, can only be set when project=libft
25+ --no-required: Optionnal, can only be set when project=libft
26+ --no-bonus: Optionnal, can only be set when project=libft
27+ --do-benchmark: Optionnal, can only be set when project=libft
28+ --no-tests: Optionnal, can only be set when project is not other.
29+ --no-libftest: Optionnal, can only be set when project=libft
30+ --no-maintest: Optionnal, can only be set when project=libft|gnl|ft_ls
31+ --no-moulitest: Optionnal, can only be set when project=libft|gnl|ft_ls|ft_printf|libftasm
32+ --no-fillit-checker: Optionnal, can only be set when project=fillit
33+ --no-libft-unit-test: Optionnal, can only be set when project=libft
34+
35+ :param args: the parsed arguments passed to the program
36+ """
37+
38+ # If no project is given the parser sends an error.
39+ if args .project is None :
40+ parser .error ("You need to specify a project." )
41+ # If the path of the selected project is empty, the parser prints an error.
42+ if args .path == "" :
43+ parser .error ("`--path' needs to be specified in order for 42PyChecker"
44+ " to know where your project is." )
45+ if args .path [0 ] != '/' :
46+ parser .error ("`--path' needs to have an absolute path" )
47+ # If a test is disabled and the libft project is selected, the parser will
48+ # return an error.
49+
50+ # Here, if the `--no-tests` option is set, all the testing suites will be
51+ # disabled, no matter the project.
52+ if args .project == "other" and args .no_tests :
53+ parser .error ("`--no-tests' Can only be applied on projects, not when 'other' is selected." )
54+ if args .no_tests :
55+ args .no_libftest = True
56+ args .no_maintest = True
57+ args .no_moulitest = True
58+ args .no_libft_unit_test = True
59+ args .no_fillit_checker = True
60+
61+ if args .no_author and args .project == "42commandements" :
62+ parser .error ("`--no-author' Can only be applied on project, but not on 42commandements." )
63+
64+ forbidden_functions_projects = ['fdf' , 'fillit' , 'ft_ls' , 'ft_p' , 'ft_printf' , 'gnl' , 'get_next_line' , 'libft' , 'libftasm' , 'libft_asm' , 'minishell' , 'pushswap' , 'push_swap' ]
65+ if args .no_forbidden_functions and args .project not in forbidden_functions_projects :
66+ parser .error ("`--no-forbidden-functions' Cannot be set if project isn't one of " + str (forbidden_functions_projects ))
67+
68+ if args .no_makefile and args .project == "42commandements" :
69+ parser .error ("`--no-makefile' Can only be applied on project, but not on 42commandements." )
70+
71+ if args .no_norm and args .project == "42commandements" :
72+ parser .error ("`--no-norm' Can only be applied on project, but not on 42commandements." )
73+
74+ if args .no_static and args .project != "libft" :
75+ parser .error ("`--no-static' Can only be applied project `libft'" )
76+
77+ if args .no_extra and args .project != "libft" :
78+ parser .error ("`--no-extra' Can only be applied project `libft'" )
79+
80+ if args .no_required and args .project != "libft" :
81+ parser .error ("`--no-required' Can only be applied project `libft'" )
82+
83+ if args .no_bonus and args .project != "libft" :
84+ parser .error ("`--no-bonus' Can only be applied project `libft'" )
85+
86+ if args .do_benchmark and args .project != "libft" :
87+ parser .error ("`--do-benchmark' Can only be applied project `libft'" )
88+
89+ if args .no_libftest and args .project != "libft" :
90+ parser .error ("`--no-libftest' can only be applied if libft is selected "
91+ "with `--project'" )
92+
93+ if args .no_maintest and args .project != "libft" :
94+ parser .error ("`--no-maintest' can only be applied if libft is selected "
95+ "with `--project'" )
96+
97+ if args .no_moulitest and args .project != "libft" :
98+ parser .error ("`--no-moulitest' can only be applied if libft is selected"
99+ " with `--project'" )
100+
101+ if args .no_libft_unit_test and args .project != "libft" :
102+ parser .error ("`--no-libft-unit-test' can only be applied if libft is selected"
103+ " with `--project'" )
104+
105+ if args .no_fillit_checker and args .project != "fillit" :
106+ parser .error ("`--no-fillit-checker' can only be applied if fillit is selected"
107+ " with `--project'" )
9108
10109
11110def print_header ():
@@ -49,12 +148,11 @@ def main():
49148 parser .add_argument ("--show-w" , help = "Displays the warranty warning from the license." , action = "store_true" )
50149 parser .add_argument ("--show-c" , help = "Displays the conditions warning from the license." , action = "store_true" )
51150 parser .add_argument ("--no-tests" , help = "Disables all the testing suites for the project." , action = "store_true" )
52- # @todo: Check what option is given based on the selected project.
53151 parser .add_argument ("--no-required" , help = "Disables required functions check" , action = "store_true" )
54152 parser .add_argument ("--no-libft-unit-test" , help = "Disables libft-unit-test" , action = "store_true" )
55153 parser .add_argument ("--do-benchmark" , help = "Enables libft-unit-test benchmarking" , action = "store_true" )
56154 parser .add_argument ("--no-fillit-checker" , help = "Disables fillit_checker" , action = "store_true" )
57-
155+ parser . add_argument ( "--no-bonus" , help = "Disables the bonus check for the libft" , action = "store_true" )
58156 # Calls the parser for the arguments we asked to implement.
59157 args = parser .parse_args ()
60158
@@ -70,51 +168,22 @@ def main():
70168 " ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS"
71169 " WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME\n "
72170 " THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION." )
73- return
171+ sys . exit ()
74172
75173 # If the `--show-c` argument is passed, the program will display the License
76174 # and exit.
77175 if args .show_c :
78176 with open (root_path + '/.github/LICENSE.lesser' , 'r' ) as file :
79177 print (file .read ())
80- return
81-
82- # Here, if the `--no-tests` option is set, all the testing suites will be
83- # disabled, no matter the project.
84- if args .no_tests :
85- args .no_libftest = True
86- args .no_maintest = True
87- args .no_moulitest = True
88- args .no_libft_unit_test = True
178+ sys .exit ()
89179
90- # If no project is given the parser sends an error.
91- if args .project is None :
92- parser .error ("You need to specify a project." )
93- # If the path of the selected project is empty, the parser prints an error.
94- if args .path == "" :
95- parser .error ("`--path' needs to be specified in order for 42PyChecker"
96- " to know where your project is." )
97- if args .path [0 ] != '/' :
98- parser .error ("`--path' needs to have an absolute path" )
99- # If a test is disabled and the libft project is selected, the parser will
100- # return an error.
101- if args .no_libftest and args .project != "libft" :
102- parser .error ("`--no-libftest' can only be applied if libft is selected "
103- "with `--project'" )
104- if args .no_maintest and args .project != "libft" :
105- parser .error ("`--no-maintest' can only be applied if libft is selected "
106- "with `--project'" )
107- if args .no_moulitest and args .project != "libft" :
108- parser .error ("`--no-moulitest' can only be applied if libft is selected"
109- " with `--project'" )
180+ check_args_rules (parser , args )
110181
111182 # Here we select the project and start the check based on the argument `--project`
112183 if args .project == "libft" :
113184 libft .check (root_path , args )
114- # @todo: Handle options for 42commandements: No option can be passed (like --no-norm)
115185 if args .project == "42commandements" :
116186 ft_commandements .check (args )
117- # @todo: Handle options for other: No option can be passed (like --no-norm)
118187 if args .project == "other" :
119188 other .check (root_path , args )
120189 if args .project == "fillit" :
0 commit comments