NeroCube / bookmark

Place some learning resources
0 stars 0 forks source link

Cookiecutter 設定必填無預設值欄位 #409

Open NeroCube opened 1 year ago

NeroCube commented 1 year ago

Cookiecutter 是一個開源的函式庫,可以用來建立程式碼專案的範本¹。您可以用任何程式語言或標記格式來定義您的範本,例如 Python、JavaScript、Ruby 等等¹。

如果您想要設定必填無預設值的 project_id 欄位,您可以在您的範本中使用 {{cookiecutter.project_id}} 來表示這個變數²。當您使用這個範本時,Cookiecutter 會提示您輸入 project_id 的值²。

您也可以在 cookiecutter.json 檔案中指定 project_id 的屬性,例如是否為必填、是否有預設值、是否有選項等等³。例如,如果您想要讓 project_id 必填且無預設值,您可以在 cookiecutter.json 檔案中寫:

{ "project_id: null }

這樣一來,Cookiecutter 會要求您輸入 project_id 的值,並且不會接受空白或空值³。

Source: Conversation with Bing, 2023/7/14 (1) GitHub - cookiecutter/cookiecutter: A cross-platform command-line utility that creates projects from cookiecutters (project templates), e.g .... https://github.com/cookiecutter/cookiecutter. (2) Cookiecutter. https://www.cookiecutter.io/. (3) API — cookiecutter 2.2.3 documentation - Read the Docs. https://cookiecutter.readthedocs.io/en/stable/cookiecutter.html. (4) undefined. https://cookiecutter.readthedocs.io. (5) undefined. https://pypi.org/project/cookiecutter/. (6) undefined. https://github.com/audreyfeldroy/cookiecutter-pypackage.