databased.create_shell
1import argparse 2 3from pathier import Pathier 4 5root = Pathier(__file__).parent 6 7 8def get_args() -> argparse.Namespace: 9 parser = argparse.ArgumentParser() 10 11 parser.add_argument("shellname", help=""" The name for the custom shell. """) 12 args = parser.parse_args() 13 14 return args 15 16 17def create_shell(name: str): 18 """Generate a template file in the current working directory for a custom DBShell class. 19 20 `name` will be used to name the generated file as well as several components in the file content.""" 21 custom_file = (Pathier.cwd() / name.replace(" ", "_")).with_suffix(".py") 22 if custom_file.exists(): 23 raise FileExistsError( 24 f"Error: {custom_file.name} already exists in this location." 25 ) 26 else: 27 variable_name = "_".join(word for word in name.lower().split()) 28 class_name = "".join(word.capitalize() for word in name.split()) 29 content = (Pathier(__file__).parent / "customshell.py").read_text() 30 content = content.replace("CustomShell", class_name) 31 content = content.replace("customshell", variable_name) 32 custom_file.write_text(content) 33 34 35def main(args: argparse.Namespace | None = None): 36 if not args: 37 args = get_args() 38 create_shell(args.shellname) 39 40 41if __name__ == "__main__": 42 main(get_args())
def
get_args() -> argparse.Namespace:
def
create_shell(name: str):
18def create_shell(name: str): 19 """Generate a template file in the current working directory for a custom DBShell class. 20 21 `name` will be used to name the generated file as well as several components in the file content.""" 22 custom_file = (Pathier.cwd() / name.replace(" ", "_")).with_suffix(".py") 23 if custom_file.exists(): 24 raise FileExistsError( 25 f"Error: {custom_file.name} already exists in this location." 26 ) 27 else: 28 variable_name = "_".join(word for word in name.lower().split()) 29 class_name = "".join(word.capitalize() for word in name.split()) 30 content = (Pathier(__file__).parent / "customshell.py").read_text() 31 content = content.replace("CustomShell", class_name) 32 content = content.replace("customshell", variable_name) 33 custom_file.write_text(content)
Generate a template file in the current working directory for a custom DBShell class.
name
will be used to name the generated file as well as several components in the file content.
def
main(args: argparse.Namespace | None = None):