diff --git a/refit/README.md b/refit/README.md index b5396d6..c21fb5f 100644 --- a/refit/README.md +++ b/refit/README.md @@ -18,7 +18,7 @@ - rework rf_create_decider() so it does not execute if no inputs are given -> valid input check back for no arguments passed? - check done in rf_create_decider() - get rid of input argument, default to current directory and and make it positional -- implement back in the valid input check +- implement back in the valid input check # Changelog diff --git a/refit/src/modules/refit_create.py b/refit/src/modules/refit_create.py index 9d51cf1..e5baef5 100644 --- a/refit/src/modules/refit_create.py +++ b/refit/src/modules/refit_create.py @@ -84,6 +84,7 @@ class Refit_Create: while n > 0: # Get number of the file(s) to create + file_number = str(n - 1) number_string = librefit.get_standard_name_number(file_number, length_n) @@ -102,9 +103,6 @@ class Refit_Create: def input_validator(self): """Function, which checks if the user input is valid""" - # NOTE: find a way on how to return 'True' when the user input - # is valid - # Check working directory if self.input is None: self.input = librefit.get_current_path(self.input) @@ -112,42 +110,68 @@ class Refit_Create: "FUNC: input_validator() MSG: No directory passed to the command, continue with current directory" ) + # Check if recursive input is an empty list + if self.recursive is not None: + if len(self.recursive) < 3: + logger.error("Recursive flag cannot be set without values.") + sys.exit(1) + # Exit the program if the -n argument is not passed if self.n is None: logger.error( - f"FUNC rf_create_decider() MSG: the number value cannot be '{self.n}'" + f"FUNC rf_create_decider(n=None ?) MSG: the number value cannot be '{self.n}'" ) print("Use the '-n' flag for the create command.") sys.exit(1) + else: + logger.debug( + f"FUNC: input_validator() MSG: valid number entered n={self.n}" + ) + return True def rf_create_decider(self): """Coordination of the 'create' sub command""" logger.debug("FUNC: rf_create_decider() MSG: Entered decider function") - # WARNING: implement the input validator and only continue with - # the decider if the validator returns true if self.input_validator(): - logger.debug("yippie") - - # Exits the program if recursive and filemode flags are set at the same time - if self.filemode: - logger.debug("DECISION filemode set, creating files instead of folders") - if self.recursive is None: - self.create_n_files(self.n, self.input, self.name) - else: - logger.error("Recursive and filemode don´t work together.") - print("Recursive and filemode don´t work together.") - - if self.recursive is None: - self.create_n_folders(self.n, self.input, self.name) - else: logger.debug( - f"FUNC: rf_create_decider(end) MSG: given arguments: {self.args}" + f"FUNC: rf_create_decider() MSG: n={self.n} after input validating" ) - print( - "Use '-n' argument to create directories.\nPlease use 'refit create -h' for help" - ) - sys.exit(1) + + # Exits the program if recursive and filemode flags are set at the same time + if self.filemode: + logger.debug( + f"FUNC: rf_create_decider(filemode) MSG: given arguments: {self.n} {self.input} {self.name}" + ) + if self.recursive is None: + self.create_n_files(self.n, self.input, self.name) + else: + logger.error("Recursive and filemode don´t work together.") + print("Recursive and filemode don´t work together.") + + if self.recursive is not None: + logger.debug( + f"FUNC: rf_create_decider(recursive) MSG: given arguments: n={self.n} input={self.input} name={self.name} recursive={self.recursive}" + ) + + # OPTIMIZE:Enters the standard creation mode and crerates directories. + if self.recursive is None: + if not self.filemode: + logger.debug( + f"FUNC: rf_create_decider(n_folder) MSG: given arguments: n={self.n} input={self.input} name={self.name}" + ) + self.create_n_folders(self.n, self.input, self.name) + else: + print("How did we end up here?????") + + else: + logger.debug( + f"FUNC: rf_create_decider(exit no input) MSG: given arguments: n={self.n} input={self.input} name={self.name} recursive={self.recursive}" + ) + print( + "Use '-n' argument to create directories.\nPlease use 'refit create -h' for help" + ) + sys.exit(1) def __call__(self): """Gets called when the 'create' subcommand is used.""" diff --git a/refit/src/refit.py b/refit/src/refit.py index 76c664c..0216905 100644 --- a/refit/src/refit.py +++ b/refit/src/refit.py @@ -22,7 +22,7 @@ def read_version_config(): if not os.path.exists(CONFIG_FILE): logger.error( - f"Func: read_version_config() MSG: Could not find config file '{CONFIG_FILE}'" + f"FUNC: read_version_config() MSG: Could not find config file '{CONFIG_FILE}'" ) return "x.x.x" @@ -82,8 +82,8 @@ create_parser.add_argument( create_parser.add_argument( "-r", "--recursive", - action="store_true", - # nargs="*", + # action="store_true", + nargs="*", help="Sets the recursive mode for folders to true. First argumet\n is for the depth and the second for the width.", ) create_parser.set_defaults(command_class=Refit_Create)