Skip to content

Commit ec7bd1a

Browse files
committed
add version argument and harmonize apps
1 parent 786675e commit ec7bd1a

File tree

9 files changed

+49
-11
lines changed

9 files changed

+49
-11
lines changed

src/apps/bin_projinfo.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(PROJINFO_SRC projinfo.cpp)
1+
set(PROJINFO_SRC projinfo.cpp emess.cpp)
22

33
source_group("Source Files\\Bin" FILES ${PROJINFO_SRC})
44

src/apps/bin_projsync.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(PROJSYNC_SRC projsync.cpp)
1+
set(PROJSYNC_SRC projsync.cpp emess.cpp)
22

33
source_group("Source Files\\Bin" FILES ${PROJSYNC_SRC})
44

src/apps/cct.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static const char usage[] = {
134134
" --inverse Alias for -I\n"
135135
" --skip-lines Alias for -s\n"
136136
" --help Alias for -h\n"
137-
" --version Print version number\n"
137+
" --version Print version\n"
138138
"--------------------------------------------------------------------------"
139139
"------\n"
140140
"Operator Specs:\n"
@@ -258,7 +258,7 @@ int main(int argc, char **argv) {
258258
proj_log_func(PJ_DEFAULT_CTX, (void *)fout, logger);
259259

260260
if (opt_given(o, "version")) {
261-
print(PJ_LOG_NONE, "%s: %s", o->progname, pj_get_release());
261+
fprintf(stdout, "%s: %s\n", o->progname, pj_get_version());
262262
free(o);
263263
return 0;
264264
}

src/apps/cs2cs.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,10 @@ int main(int argc, char **argv) {
426426
/* process run line arguments */
427427
while (--argc > 0) { /* collect run line arguments */
428428
++argv;
429-
if (strcmp(*argv, "--area") == 0) {
429+
if (strcmp(*argv, "--version") == 0) {
430+
(void)fprintf(stdout, "%s: %s\n", emess_dat.Prog_name, pj_get_version());
431+
exit(0);
432+
} else if (strcmp(*argv, "--area") == 0) {
430433
++argv;
431434
--argc;
432435
if (argc == 0) {

src/apps/geod.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ int main(int argc, char **argv) {
245245
case 'p': /* output azimuths as positive */
246246
pos_azi = 1;
247247
continue;
248+
case '-': /* long option */
249+
if (strcmp(*argv, "--version") == 0) {
250+
(void)fprintf(stdout, "%s: %s\n", emess_dat.Prog_name, pj_get_version());
251+
exit(0);
252+
}
253+
else {
254+
emess(1, "invalid option: %s", *argv);
255+
break;
256+
}
248257
default:
249258
emess(1, "invalid option: -%c", *arg);
250259
break;

src/apps/gie.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static const char usage[] = {
249249
" --verbose Alias for -v\n"
250250
" --help Alias for -h\n"
251251
" --list Alias for -l\n"
252-
" --version Print version number\n"
252+
" --version Print version\n"
253253
"--------------------------------------------------------------------------"
254254
"------\n"
255255
"Examples:\n"
@@ -267,7 +267,8 @@ static const char usage[] = {
267267
int main(int argc, char **argv) {
268268
int i;
269269
const char *longflags[] = {"v=verbose", "q=quiet", "h=help",
270-
"l=list", "version", nullptr};
270+
"l=list", "version",
271+
nullptr};
271272
const char *longkeys[] = {"o=output", nullptr};
272273
OPTARGS *o;
273274

@@ -290,7 +291,7 @@ int main(int argc, char **argv) {
290291
}
291292

292293
if (opt_given(o, "version")) {
293-
fprintf(stdout, "%s: %s\n", o->progname, pj_get_release());
294+
fprintf(stdout, "%s: %s\n", o->progname, pj_get_version());
294295
free(o);
295296
return 0;
296297
}

src/apps/proj.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ int main(int argc, char **argv) {
505505
continue;
506506
case '-': /* long option */
507507
if (strcmp(*argv, "--version") == 0) {
508-
(void)printf("%s\n", pj_get_version());
508+
(void)fprintf(stdout, "%s: %s\n", emess_dat.Prog_name, pj_get_version());
509509
exit(0);
510510
}
511511
else {

src/apps/projinfo.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include "proj.h"
4141
#include "proj_internal.h"
42+
#include "emess.h"
4243

4344
#include <proj/common.hpp>
4445
#include <proj/coordinateoperation.hpp>
@@ -1399,6 +1400,11 @@ int main(int argc, char **argv) {
13991400
std::cerr << pj_get_release() << std::endl;
14001401
usage();
14011402
}
1403+
1404+
if ((emess_dat.Prog_name = strrchr(*argv, '/')) != nullptr)
1405+
++emess_dat.Prog_name;
1406+
else
1407+
emess_dat.Prog_name = *argv;
14021408

14031409
if (argc >= 3 && strcmp(argv[1], "completion") == 0) {
14041410
suggestCompletion(std::vector<std::string>(argv + 3, argv + argc));
@@ -1447,7 +1453,12 @@ int main(int argc, char **argv) {
14471453

14481454
for (int i = 1; i < argc; i++) {
14491455
std::string arg(argv[i]);
1450-
if (arg == "-o" && i + 1 < argc) {
1456+
if (arg == "--version")
1457+
{
1458+
std::cout << emess_dat.Prog_name << ": " << pj_get_version() << std::endl;
1459+
std::exit(0);
1460+
}
1461+
else if (arg == "-o" && i + 1 < argc) {
14511462
outputSwitchSpecified = true;
14521463
i++;
14531464
const auto formats(split(argv[i], ','));

src/apps/projsync.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "filemanager.hpp"
4040
#include "proj.h"
4141
#include "proj_internal.h"
42+
#include "emess.h"
4243

4344
#include "proj/internal/include_nlohmann_json.hpp"
4445
#include "proj/internal/internal.hpp"
@@ -76,6 +77,9 @@ class ParsingException : public std::exception {
7677
std::cerr << " [--quiet | --verbose] [--dry-run] [--list-files]"
7778
<< std::endl;
7879
std::cerr << " [--no-version-filtering]" << std::endl;
80+
std::cerr << " [--version]" << std::endl;
81+
std::cerr << " [--release]" << std::endl;
82+
std::cerr << " [--short-version]" << std::endl;
7983
std::exit(1);
8084
}
8185

@@ -116,6 +120,11 @@ int main(int argc, char *argv[]) {
116120

117121
auto ctx = pj_get_default_ctx();
118122

123+
if ((emess_dat.Prog_name = strrchr(*argv, '/')) != nullptr)
124+
++emess_dat.Prog_name;
125+
else
126+
emess_dat.Prog_name = *argv;
127+
119128
std::string targetDir;
120129
std::string endpoint(proj_context_get_url_endpoint(ctx));
121130
const std::string geojsonFile("files.geojson");
@@ -139,7 +148,12 @@ int main(int argc, char *argv[]) {
139148

140149
for (int i = 1; i < argc; i++) {
141150
std::string arg(argv[i]);
142-
if (arg == "--endpoint" && i + 1 < argc) {
151+
if (arg == "--version")
152+
{
153+
std::cout << emess_dat.Prog_name << ": " << pj_get_version() << std::endl;
154+
std::exit(0);
155+
}
156+
else if (arg == "--endpoint" && i + 1 < argc) {
143157
i++;
144158
endpoint = argv[i];
145159
} else if (arg == "--user-writable-directory") {

0 commit comments

Comments
 (0)