diff --git a/refit/src/modules/refit_create.py b/refit/src/modules/refit_create.py index b9d545f..040edc0 100644 --- a/refit/src/modules/refit_create.py +++ b/refit/src/modules/refit_create.py @@ -22,6 +22,7 @@ class Refit_Create: self.n = args.n self.filemode = args.filemode self.recursive = args.recursive + self.e = args.e def create_n_folders(self, n, input, name): """Creates an set ammount of folders. Using the default directory @@ -50,7 +51,7 @@ class Refit_Create: os.mkdir(folder_creation_path) n -= 1 - def create_n_files(self, n, input, name): + def create_n_files(self, n, input, name, file_extension): """Creates an set ammount of files, using the default file name if none is provided.""" @@ -71,7 +72,10 @@ class Refit_Create: number_string = librefit.get_standard_name_number(file_number, length_n) # Get the name of the file, either applying default or using first list item. - temp_name = f"{file_name}_{number_string}" + if file_extension is not None: + temp_name = f"{file_name}_{number_string}.{file_extension}" + else: + temp_name = f"{file_name}_{number_string}" file_path = Path(os.path.join(input, temp_name)) # Build file path file_path.touch(exist_ok=True) # creating file @@ -127,19 +131,18 @@ class Refit_Create: def create_dispatcher(self): """Coordination of the 'create' sub command""" - logger.debug("FUNC: create_dispatcher() MSG: Entered decider function") + logger.debug( + f"FUNC: create_dispatcher() MSG: Entered decider function {self.args}" + ) if self.input_validator(): if self.filemode: logger.debug( - f"FUNC: create_dispatcher(filemode) MSG: given arguments: n={self.n} input={self.input} name={self.name}" + f"FUNC: create_dispatcher(filemode) MSG: given arguments: n={self.n} input={self.input} name={self.name} file_extension={self.e}" ) - self.create_n_files(self.n, self.input, self.name) + self.create_n_files(self.n, self.input, self.name, self.e) elif self.recursive is not None: - # NOTE: for the dynamic name use two more args, if they - # exist, take them as name for the two dirs. else use - # default names logger.debug( f"FUNC: create_dispatcher(recursive) MSG: given arguments: n={self.n} input={self.input} name={self.name} recursive={self.recursive}" ) diff --git a/refit/src/refit.py b/refit/src/refit.py index 74db541..21bba89 100644 --- a/refit/src/refit.py +++ b/refit/src/refit.py @@ -78,6 +78,7 @@ create_parser.add_argument( nargs=2, help="Sets the recursive mode for folders to true. First argumet is for the depth and the second for the width.", ) +create_parser.add_argument("-e", help="File extension") create_parser.set_defaults(command_class=Refit_Create) args = parser.parse_args()