-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inject and display version info (#25)
- Loading branch information
1 parent
0663ae4
commit 6bbeeb5
Showing
8 changed files
with
96 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
VERSION=$(git tag --points-at HEAD | head -1) | ||
if [ -z "$VERSION" ]; then | ||
VERSION=$(git rev-parse HEAD | cut -c 1-7) | ||
fi | ||
|
||
echo $VERSION | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <getopt.h> | ||
#include <stdio.h> | ||
|
||
int version_option(int argc, char *argv[], char *version, FILE *fp) | ||
{ | ||
int f_version = 0; | ||
int option_index = 0; | ||
int return_code = 0; | ||
struct option long_options[] = | ||
{ | ||
{ "version", no_argument, &f_version, 1 }, | ||
{ NULL, 0, NULL, 0 } | ||
}; | ||
|
||
if (getopt_long(argc, argv, "-:v", long_options, &option_index) == 'v' || f_version == 1) | ||
{ | ||
fprintf(fp, "ga-cmd version %s\n", version); | ||
return_code = 1; | ||
} | ||
|
||
return return_code; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
int version_option(int , char *[], char *, FILE *); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <getopt.h> | ||
#include <stdio.h> | ||
#include "version.h" | ||
|
||
int TEST_version_option() | ||
{ | ||
char *version_string = "test-version"; | ||
char *arg_zero = "test-cmd"; | ||
char *args[] = { arg_zero, "--version" }; | ||
FILE *fp; | ||
int actual_result; | ||
int return_code = 0; | ||
|
||
fp = fopen("/dev/null", "w"); | ||
|
||
actual_result = version_option(2, args, version_string, fp); | ||
if (!actual_result) | ||
{ | ||
printf("FAIL: Version should be shown when --version flag is given\n"); | ||
return_code = 1; | ||
} | ||
|
||
optind = 1; | ||
args[1] = "-v"; | ||
actual_result = version_option(2, args, version_string, fp); | ||
if (!actual_result) | ||
{ | ||
printf("FAIL: Version should be shown when -v flag is given\n"); | ||
return_code = 1; | ||
} | ||
|
||
optind = 1; | ||
args[1] = NULL; | ||
actual_result = version_option(1, args, version_string, fp); | ||
if (actual_result) | ||
{ | ||
printf("FAIL: Version should not be shown when no flag is given\n"); | ||
return_code = 1; | ||
} | ||
|
||
fclose (fp); | ||
|
||
return return_code; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
int TEST_version_option(); | ||
|