aboutsummaryrefslogtreecommitdiff
path: root/src/cli
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2026-04-20 12:50:39 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2026-04-21 12:22:04 -0400
commit7f4918f1f17b0ddde6d1a8435e63f5f94c6dd065 (patch)
tree2981bfd281eaeb91e631fe037767decd72a85aab /src/cli
parente05702d1818088439fd017786a036103062db358 (diff)
downloadstasis-7f4918f1f17b0ddde6d1a8435e63f5f94c6dd065.tar.gz
Generate version string based on repository information
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/stasis/stasis_main.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/cli/stasis/stasis_main.c b/src/cli/stasis/stasis_main.c
index 328d825..697791a 100644
--- a/src/cli/stasis/stasis_main.c
+++ b/src/cli/stasis/stasis_main.c
@@ -487,6 +487,39 @@ static void transfer_artifacts(struct Delivery *ctx) {
}
}
+static char *center_text(const char *s, const size_t maxwidth) {
+ if (maxwidth < 2) {
+ SYSERROR("%s", "maximum width must be greater than 0");
+ return NULL;
+ }
+
+ if (maxwidth % 2 != 0) {
+ SYSERROR("maximum width (%zu) must be even", maxwidth);
+ return NULL;
+ }
+
+ const size_t s_len = strlen(s);
+ if (s_len + 1 > maxwidth) {
+ SYSERROR("length of input string (%zu) exceeds maximum width (%zu)", s_len, maxwidth);
+ return NULL;
+ }
+
+ char *result = calloc(maxwidth + 1, sizeof(*result));
+ if (!result) {
+ SYSERROR("%s", "unable to allocate bytes for centered text string");
+ return NULL;
+ }
+ const size_t middle = (maxwidth / 2) - s_len / 2;
+ size_t i = 0;
+ for (; i < middle; i++) {
+ result[i] = ' ';
+ }
+ result[i++] = 'v';
+ strncpy(&result[i], s, maxwidth - middle - 1);
+ return result;
+}
+
+
int main(int argc, char *argv[]) {
struct Delivery ctx;
struct Process proc = {
@@ -634,7 +667,17 @@ int main(int argc, char *argv[]) {
exit(1);
}
- printf(BANNER, VERSION, AUTHOR);
+ char *version = center_text(VERSION, strlen(STASIS_BANNER_HEADER));
+ if (!version) {
+ SYSERROR("%s", "version too long?");
+ version = strdup(VERSION);
+ if (!version) {
+ SYSERROR("%s", "unable to allocate uncentered fallback version string");
+ exit(1);
+ }
+ }
+ printf(BANNER, version, AUTHOR);
+ guard_free(version);
setup_python_version_override(&ctx, python_override_version);
configure_stasis_ini(&ctx, &config_input);