nautobot / cookiecutter-nautobot-app

Cookiecutter template for creating new Nautobot Apps.
https://docs.nautobot.com/projects/cookiecutter-nautobot-app/en/latest/
Apache License 2.0
16 stars 5 forks source link

Change Default Behavior to Create Model Example #190

Open bryanculver opened 1 week ago

bryanculver commented 1 week ago

Provide the user the option to override the initial model name created but the current default behavior skips generating these files which then gets lost when managing drift as well as forces the user to manually create these files, often far adrift from standard.

https://github.com/nautobot/cookiecutter-nautobot-app/blob/566d869ef93f461214aedb55c0f4cddada41e415/nautobot-app/hooks/post_gen_project.py#L27-L48

To resolve the "missed when drift managed" issue in other Apps, update the .cookiecutter.json file in the repo to have model_class_name be the name of one of the models in the App (ex: "model_class_name": "GoldenConfig" for Golden Config). The value should be left as "None" for any App that does not contain any models.

gsnider2195 commented 1 week ago

It looks like cookiecutter doesn't provide us with any advanced prompt manipulation so I propose we set the default model_class_name to {{ cookiecutter.camel_name }}ExampleModel }} and modify the prompt to let the user know to set it to None for no model:

{
    "codeowner_github_usernames": "",
    "full_name": "Network to Code, LLC",
    "email": "info@networktocode.com",
    "github_org": "nautobot",
    "app_name": "my_app",
    "verbose_name": "{{ cookiecutter.app_name.title().replace('_', ' ') }}",
    "app_slug": "{{ cookiecutter.app_name.lower().replace(' ', '-').replace('_', '-') }}",
    "project_slug": "nautobot-app-{{ cookiecutter.app_slug }}",
    "repo_url": "https://github.com/{{ cookiecutter.github_org }}/{{ cookiecutter.project_slug }}",
    "base_url": "{{ cookiecutter.app_slug }}",
    "min_nautobot_version": "2.0.0",
    "max_nautobot_version": "2.9999",
    "camel_name": "{{ cookiecutter.app_slug.title().replace(' ', '').replace('-', '') }}",
    "project_short_description": "{{ cookiecutter.verbose_name }}",
    "model_class_name": "{{ cookiecutter.camel_name }}ExampleModel",
    "open_source_license": [
        "Apache-2.0",
        "Not open source"
    ],
    "docs_base_url": "https://docs.nautobot.com",
    "docs_app_url": "{{ cookiecutter.docs_base_url }}/projects/{{ cookiecutter.app_slug }}/en/latest",
    "__prompts__": {
        "model_class_name": "Select the name of your first database model. Set to 'None' if this app will have no models."
    }
}
smk4664 commented 6 days ago