Skip to content

Commit

Permalink
CLI option to print version
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Kalatozishvili committed Aug 16, 2023
1 parent 4ce2050 commit 9b8e34f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static xbool_t SMake_AddFindObject(smake_ctx_t *pCtx, xjson_obj_t *pFindObj, xbo
int SMake_ParseArgs(smake_ctx_t *pCtx, int argc, char *argv[])
{
int nChar = 0;
while ((nChar = getopt(argc, argv, "o:s:c:e:b:i:f:g:l:p:v:L:I1:d1:j1:w1:x1:h1")) != -1)
while ((nChar = getopt(argc, argv, "o:s:c:e:b:i:f:g:l:p:v:L:V1:I1:d1:j1:w1:x1:h1")) != -1)
{
switch (nChar)
{
Expand Down Expand Up @@ -294,6 +294,9 @@ int SMake_ParseArgs(smake_ctx_t *pCtx, int argc, char *argv[])
case 'I':
pCtx->bInitProj = XTRUE;
break;
case 'V':
SMake_PrintVersion(argv[0]);
return XFALSE;
case 'h':
default:
SMake_Usage(argv[0]);
Expand Down
16 changes: 11 additions & 5 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ const char* SMake_VersionShort()
return sVersion;
}

void SMake_PrintVersion(const char *pName)
{
printf("%s - v%s (email: s.kalatoz@gmail.com)\n", pName, SMake_Version());
}

void SMake_Greet(const char *pName)
{
printf("=============================================================================\n");
printf("%s Version: %s (email: s.kalatoz@gmail.com)\n", pName, SMake_Version());
SMake_PrintVersion(pName);
printf("=============================================================================\n");
}

Expand All @@ -52,9 +57,9 @@ void SMake_Usage(const char *pName)
SMake_Greet(SMAKE_FULL_NAME);
int nLength = strlen(pName) + 6;

printf("Usage: %s [-f <'flags'>] [-b <path>] [-i <path>] [-c <path>] [-I]\n", pName);
printf(" %s [-l <'libs'>] [-e <paths>] [-g <name>] [-o <path>] [-j] \n", WhiteSpace(nLength));
printf(" %s [-L <'libs'>] [-p <name>] [-s <path>] [-d] [-v] [-w] [-x] [-h]\n", WhiteSpace(nLength));
printf("Usage: %s [-f <'flags'>] [-b <path>] [-i <path>] [-c <path>] [-I] [-V]\n", pName);
printf(" %s [-l <'libs'>] [-e <paths>] [-g <name>] [-o <path>] [-d] [-j]\n", WhiteSpace(nLength));
printf(" %s [-L <'libs'>] [-p <name>] [-s <path>] [-v <numb>] [-w] [-x] [-h]\n", WhiteSpace(nLength));
printf("Options are:\n");
printf(" -f <'flags'> # Compiler flags\n");
printf(" -l <'libs'> # Linked libraries\n");
Expand All @@ -67,10 +72,11 @@ void SMake_Usage(const char *pName)
printf(" -o <path> # Object output destination\n");
printf(" -p <name> # Program or library name\n");
printf(" -s <path> # Path to source files\n");
printf(" -v <numb> # Verbosity level\n");
printf(" -V # Print version and exit\n");
printf(" -I # Initialize project\n");
printf(" -j # Generate smake.json\n");
printf(" -d # Virtual directory\n");
printf(" -v # Verbosity level\n");
printf(" -w # Force overwrite output\n");
printf(" -x # Create Makefile for CPP\n");
printf(" -h # Print version and usage\n\n");
Expand Down
3 changes: 2 additions & 1 deletion src/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#define SMAKE_VERSION_MAX 1
#define SMAKE_VERSION_MIN 1
#define SMAKE_BUILD_NUMBER 17
#define SMAKE_BUILD_NUMBER 18

#ifndef _SMAKE_VERSION_H_
#define _SMAKE_VERSION_H_
Expand All @@ -26,6 +26,7 @@ const char* SMake_VersionShort();

void SMake_Greet(const char *pName);
void SMake_Usage(const char *pName);
void SMake_PrintVersion(const char *pName);

/* For include header in CPP code */
#ifdef __cplusplus
Expand Down
9 changes: 7 additions & 2 deletions src/smake.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ int main(int argc, char *argv[])
smake_ctx_t smake;
SMake_InitContext(&smake);

if (!SMake_ParseArgs(&smake, argc, argv) ||
!SMake_ParseConfig(&smake) ||
if (!SMake_ParseArgs(&smake, argc, argv))
{
SMake_ClearContext(&smake);
return XSTDNON;
}

if (!SMake_ParseConfig(&smake) ||
!SMake_InitProject(&smake) ||
!SMake_LoadFiles(&smake, NULL) ||
!SMake_ParseProject(&smake) ||
Expand Down

0 comments on commit 9b8e34f

Please sign in to comment.