|
12 | 12 | from rpdk.core.jsonutils.resolver import resolve_models |
13 | 13 | from rpdk.core.plugin_base import LanguagePlugin |
14 | 14 |
|
| 15 | +from . import __version__ |
15 | 16 | from .resolver import translate_type |
16 | 17 | from .utils import safe_reserved, validate_path |
| 18 | +from .version import check_version |
17 | 19 |
|
18 | 20 | LOG = logging.getLogger(__name__) |
19 | 21 |
|
20 | 22 | OPERATIONS = ("Create", "Read", "Update", "Delete", "List") |
21 | 23 | EXECUTABLE = "cfn-cli" |
22 | 24 |
|
| 25 | +LANGUAGE = "go" |
| 26 | + |
| 27 | +DEFAULT_SETTINGS = { |
| 28 | + "protocolVersion": "1.0", |
| 29 | + "pluginVersion": __version__, |
| 30 | +} |
| 31 | + |
23 | 32 |
|
24 | 33 | class GoExecutableNotFoundError(SysExitRecommendedError): |
25 | 34 | pass |
@@ -121,6 +130,7 @@ def _init_settings(self, project): |
121 | 130 | project.runtime = self.RUNTIME |
122 | 131 | project.entrypoint = self.ENTRY_POINT.format(self.import_path) |
123 | 132 | project.test_entrypoint = self.TEST_ENTRY_POINT.format(self.import_path) |
| 133 | + project.settings.update(DEFAULT_SETTINGS) |
124 | 134 |
|
125 | 135 | def init_handlers(self, project, src): |
126 | 136 | LOG.debug("Writing stub handlers") |
@@ -172,6 +182,23 @@ def generate(self, project): |
172 | 182 | except (FileNotFoundError, CalledProcessError) as e: |
173 | 183 | raise DownstreamError("go fmt failed") from e |
174 | 184 |
|
| 185 | + # Update settings as needed |
| 186 | + need_to_write = False |
| 187 | + for key, new in DEFAULT_SETTINGS.items(): |
| 188 | + old = project.settings.get(key) |
| 189 | + |
| 190 | + if project.settings.get(key) != new: |
| 191 | + LOG.debug(f"{key} version change from {old} to {new}") |
| 192 | + project.settings[key] = new |
| 193 | + need_to_write = True |
| 194 | + |
| 195 | + if key == "pluginVersion": |
| 196 | + # Display any upgrade messages |
| 197 | + print(*check_version(old), sep="\n") |
| 198 | + |
| 199 | + if need_to_write: |
| 200 | + project._write_settings(LANGUAGE) |
| 201 | + |
175 | 202 | @staticmethod |
176 | 203 | def pre_package(project): |
177 | 204 | # zip the Go build output - it's all needed to execute correctly |
|
0 commit comments