Skip to content

Commit 41bf8c0

Browse files
committed
feat: add -V/--version flag
1 parent 00d660c commit 41bf8c0

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
cmake_minimum_required(VERSION 3.20)
22

3-
project(sshpass)
3+
project(sshpass VERSION 1.0.7)
44

55
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
66

77
add_executable(${PROJECT_NAME} main.c argparse.c)
88
add_compile_options(/W4 /utf8)
9+
target_compile_definitions(${PROJECT_NAME} PRIVATE SSHPASS_VERSION="${PROJECT_VERSION}")
910
set_property(TARGET ${PROJECT_NAME} PROPERTY
1011
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
1112

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ winget install xhcoding.sshpass-win32
2222
Usage: sshpass [ options ] command arguments
2323

2424
-h, --help show this help message and exit
25+
-V, --version Print version information
2526

2627
Password options: With no options - password will be taken from stdin
2728
-f=<str> Take password to use from file

main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,11 @@ static void ParseArgs(int argc, const wchar_t* wargv[], char** argv, Context* ct
208208
int autoConfirm = 0;
209209
int totalArgc = argc;
210210

211+
int showVersion = 0;
212+
211213
struct argparse_option options[] = {
212214
OPT_HELP(),
215+
OPT_BOOLEAN('V', "version", &showVersion, "Print version information", NULL, 0, 0),
213216
OPT_GROUP("Password options: With no options - password will be taken from stdin"),
214217
OPT_STRING('f', NULL, &filename, "Take password to use from file", NULL, 0, 0),
215218
OPT_INTEGER('d', NULL, &number, "Use number as file descriptor for getting password",
@@ -230,6 +233,12 @@ static void ParseArgs(int argc, const wchar_t* wargv[], char** argv, Context* ct
230233
struct argparse argparse;
231234
argparse_init(&argparse, options, usages, ARGPARSE_STOP_AT_NON_OPTION);
232235
argc = argparse_parse(&argparse, argc, (const char**)argv);
236+
237+
if (showVersion) {
238+
fprintf(stdout, "sshpass-win32 %s\n", SSHPASS_VERSION);
239+
exit(EXIT_SUCCESS);
240+
}
241+
233242
if (argc == 0) {
234243
argparse_usage(&argparse);
235244
exit(EXIT_FAILURE);

0 commit comments

Comments
 (0)