From d08f811dcfdbdd8dae40a6850c13a0012b22d45c Mon Sep 17 00:00:00 2001 From: Greg Gibeling Date: Tue, 1 Apr 2025 15:29:28 -0700 Subject: [PATCH] G2-1745 Add support for exit codes & v0.0.2 release --- README.md | 15 +++++++++++++-- clireport.c | 18 ++++++++++++++++-- pom.xml | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7a40f1f..c59e29e 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,15 @@ A tool to report CLI arguments. ``` cl clireport.c clireport.exe A B +clireport.exe --exit 1 A B ``` ## Linux ``` docker run --rm -v "$(pwd):/clireport" -w /clireport gcc:latest gcc -o clireport clireport.c -docker run --rm -v "$(pwd):/clireport" -w /clireport ubuntu:latest /clireport/clireport A B +docker run --rm -v "$(pwd):/clireport" -w /clireport ubuntu:latest bash -c '/clireport/clireport A B; echo $?' +docker run --rm -v "$(pwd):/clireport" -w /clireport ubuntu:latest bash -c '/clireport/clireport --exit 1 A B; echo $?' ``` ## Docker @@ -23,5 +25,14 @@ docker run --rm -v "$(pwd):/clireport" -w /clireport ubuntu:latest /clireport/cl ``` docker build --tag=ghcr.io/g2forge/clireport:latest . docker run ghcr.io/g2forge/clireport:latest A B +docker run ghcr.io/g2forge/clireport:latest --exit 1 A B docker push ghcr.io/g2forge/clireport:latest -``` \ No newline at end of file +``` + +# Release + +1. Update [pom.xml](pom.xml) to remove `-SNAPSHOT`, and commit. +2. Update [pom.xml](pom.xml) to update version and re-add `-SNAPSHOT`, and commit. +3. Open a PR +4. Create github release and upload pre-built binaries, tagging the commit created in step 1. +5. Update `HCLIReport` to use the new release, and to match any changes to the command line argument handling or expected output diff --git a/clireport.c b/clireport.c index 42c299c..2cd7826 100644 --- a/clireport.c +++ b/clireport.c @@ -1,12 +1,26 @@ #include #include +#include +#include -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { printf("CLIReport: %d arguments\n", argc); for (int i = 0; i < argc; i++) { char* argument = argv[i]; printf("%04d: %s\n", (unsigned)strlen(argument), argument); } + + if ((strncmp(argv[1], "--exit", 7) == 0) && (argc >= 3)) { + char *endptr = NULL; + errno = 0; + int exitCode = (int) strtol(argv[2], &endptr, 10); + + if ((errno != 0) || *endptr) { + printf ("Exit code \"%s\" is not valid\n", argv[2]); + } + + return exitCode; + } + return 0; } diff --git a/pom.xml b/pom.xml index 2cda8ba..0c6204b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.g2forge.clireport clireport pom - 0.0.2-SNAPSHOT + 0.0.2 g2forge