11"""CLI functionality to customize the template."""
2- import os
3- import sys
4- from pathlib import Path
2+
3+ from datetime import date
54
65import asyncclick as click
76import tomli
87import tomli_w
98from jinja2 import Template
109from rich import print
1110
12- from config .helpers import LICENCES , template
13-
14-
15- def get_config_path ():
16- """Return the full path of the custom config file."""
17- script_dir = Path (os .path .dirname (os .path .realpath (sys .argv [0 ])))
18- return script_dir / "config" / "metadata.py"
19-
20-
21- def get_toml_path ():
22- """Return the full path of the pyproject.toml."""
23- script_dir = Path (os .path .dirname (os .path .realpath (sys .argv [0 ])))
24- return script_dir / "pyproject.toml"
11+ from config .helpers import (
12+ LICENCES ,
13+ get_api_version ,
14+ get_config_path ,
15+ get_toml_path ,
16+ template ,
17+ )
2518
2619
2720def init ():
@@ -36,6 +29,8 @@ def init():
3629 },
3730 "author" : "Grant Ramsay (seapagan)" ,
3831 "website" : "https://www.gnramsay.com" ,
32+ "email" : "seapagan@gmail.com" ,
33+ "this_year" : date .today ().year ,
3934 }
4035
4136 out = Template (template ).render (data )
@@ -80,7 +75,7 @@ def choose_license():
8075
8176 while choice .strip ().lower () not in [lic .lower () for lic in license_list ]:
8277 choice = click .prompt (
83- f"\n Choose a license from the following options. \n "
78+ f"\n Choose a license from the following options: \n "
8479 f"{ license_strings } \n Your Choice of License?" ,
8580 type = str ,
8681 default = custom_metadata .license_info ["name" ],
@@ -89,6 +84,18 @@ def choose_license():
8984 return get_case_insensitive_dict (choice )
9085
9186
87+ def choose_version (current_version ):
88+ """Change the version or reset it."""
89+ choice = click .prompt (
90+ "Version Number (use * to reset to '0.0.1')" ,
91+ type = str ,
92+ default = current_version ,
93+ )
94+ if choice == "*" :
95+ return "0.0.1"
96+ return choice
97+
98+
9299@click .group (name = "custom" )
93100def customize_group ():
94101 """Customize the Template Strings and Metadata.
@@ -105,6 +112,7 @@ def metadata():
105112 Documentation, Author details, Repository URL and more.
106113 """
107114 print ("\n [green]API-Template : Customize application Metadata\n " )
115+
108116 data = {
109117 "title" : click .prompt (
110118 "Enter your API title" , type = str , default = custom_metadata .title
@@ -114,6 +122,7 @@ def metadata():
114122 type = str ,
115123 default = custom_metadata .description ,
116124 ),
125+ "version" : choose_version (get_api_version ()),
117126 "repo" : click .prompt (
118127 "URL to your Repository" ,
119128 type = str ,
@@ -136,14 +145,19 @@ def metadata():
136145 default = custom_metadata .contact ["url" ],
137146 ),
138147 }
148+
149+ data ["this_year" ] = date .today ().year
150+
139151 print ("\n You have entered the following data:" )
140152 print (f"[green]Title : [/green]{ data ['title' ]} " )
141153 print (f"[green]Description : [/green]{ data ['desc' ]} " )
154+ print (f"[green]Version : [/green]{ data ['version' ]} " )
142155 print (f"[green]Repository : [/green]{ data ['repo' ]} " )
143156 print (f"[green]License : [/green]{ data ['license' ]['name' ]} " )
144157 print (f"[green]Author : [/green]{ data ['author' ]} " )
145158 print (f"[green]Email : [/green]{ data ['email' ]} " )
146159 print (f"[green]Website : [/green]{ data ['website' ]} " )
160+ print (f"[green](C) Year : [/green]{ data ['this_year' ]} " )
147161
148162 if click .confirm ("\n Is this Correct?" , abort = True , default = True ):
149163 # write the metadata
@@ -161,6 +175,7 @@ def metadata():
161175 with open (get_toml_path (), "rb" ) as f :
162176 config = tomli .load (f )
163177 config ["tool" ]["poetry" ]["name" ] = data ["title" ]
178+ config ["tool" ]["poetry" ]["version" ] = data ["version" ]
164179 config ["tool" ]["poetry" ]["description" ] = data ["desc" ]
165180 config ["tool" ]["poetry" ]["authors" ] = [
166181 f"{ data ['author' ]} <{ data ['email' ]} >"
0 commit comments