Skip to content

Commit

Permalink
Added option '-v, --version' to all utility applications.
Browse files Browse the repository at this point in the history
  • Loading branch information
alfmep committed Aug 4, 2022
1 parent fca2c5c commit a29448d
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 33 deletions.
10 changes: 8 additions & 2 deletions utils/ujson-cmp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Dan Arrhenius <dan@ultramarin.se>
* Copyright (C) 2021,2022 Dan Arrhenius <dan@ultramarin.se>
*
* This file is part of ujson.
*
Expand Down Expand Up @@ -53,6 +53,7 @@ static void print_usage_and_exit (std::ostream& out, int exit_code)
<< "Options:" <<endl
<< " -r, --relaxed Parse JSON documents in relaxed mode." << endl
<< " -q, --quiet Silent mode, don't write anything to standard output." << endl
<< " -v, --version Print version and exit." << endl
<< " -h, --help Print this help message and exit." << endl
<< endl;
exit (exit_code);
Expand All @@ -66,10 +67,11 @@ static void parse_args (int argc, char* argv[], appargs_t& args)
struct option long_options[] = {
{ "relaxed", no_argument, 0, 'r'},
{ "quiet", no_argument, 0, 'q'},
{ "version", no_argument, 0, 'v'},
{ "help", no_argument, 0, 'h'},
{ 0, 0, 0, 0}
};
const char* arg_format = "rqh";
const char* arg_format = "rqvh";

while (1) {
int c = getopt_long (argc, argv, arg_format, long_options, NULL);
Expand All @@ -82,6 +84,10 @@ static void parse_args (int argc, char* argv[], appargs_t& args)
case 'q':
args.quiet = true;
break;
case 'v':
std::cout << prog_name << ' ' << PACKAGE_VERSION << std::endl;
exit (0);
break;
case 'h':
print_usage_and_exit (std::cout, 0);
break;
Expand Down
14 changes: 10 additions & 4 deletions utils/ujson-cmp.man
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Parse JSON documents in relaxed mode.
.B -q, --quiet
Silent mode, don't write anything to standard output.
.TP
.B -v, --version
Print version and exit.
.TP
.B -h, --help
Print help and exit.

Expand All @@ -36,13 +39,13 @@ The following is allowed in JSON documents when relaxed format is used:
.nf
- C-style comments.
- String values can be split up into more than one string separated by whitespace or comments.
- When parsing a number, the identifiers nan and (+/-)inf/infinite are allowed.
- When parsing a number, the special values nan and (+/-)inf/infinite are allowed.
- Object definitions are allowed to end with a separator(,).
- Array items are allowed to end with a separator(,).
- In object definitions, a member name can be an identifier instead of a string.
An identifier is a name in the following format: [_a-zA-Z][_a-zA-Z0-9]*
Exceptions are: nan, inf, and infinite (case insensitive).
Those names are reserved for numbers and are not allowed to be used as identifiers.
An identifier is a name with the following format: [_a-zA-Z][_a-zA-Z0-9]*
Exceptions are: true, false, null, nan, inf, and infinite (case insensitive).
Those names are reserved and are not allowed to be used as identifiers (i.e. without enclosing double quotes).

.PP
Example of a JSON document that is allowed in relaxed mode:
Expand All @@ -59,6 +62,9 @@ Example of a JSON document that is allowed in relaxed mode:
not_a_number: NaN,
"normal_member_name": "Another string",
// The following object member name must be enclosed by double quotes
"null": 0,
long_string: "This is a string value on " // This can be used to
"more than one line that, " // make it more readable.
"when parsed, will be one "
Expand Down
18 changes: 12 additions & 6 deletions utils/ujson-get.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Dan Arrhenius <dan@ultramarin.se>
* Copyright (C) 2021,2022 Dan Arrhenius <dan@ultramarin.se>
*
* This file is part of ujson.
*
Expand Down Expand Up @@ -64,6 +64,7 @@ static void print_usage_and_exit (std::ostream& out, int exit_code)
out << " TYPE is one of the following: boolean, number, string, null, object, or array." << endl;
out << " If the value is of a different type, exit with code 1." << endl;
out << " -r, --relaxed Parse the JSON document in relaxed mode." << endl;
out << " -v, --version Print version and exit." << endl;
out << " -h, --help Print this help message and exit." << endl;
out << endl;
exit (exit_code);
Expand All @@ -75,13 +76,14 @@ static void print_usage_and_exit (std::ostream& out, int exit_code)
static void parse_args (int argc, char* argv[], appargs_t& args)
{
struct option long_options[] = {
{ "compact", no_argument, 0, 'c'},
{ "type", required_argument, 0, 't'},
{ "relaxed", no_argument, 0, 'r'},
{ "help", no_argument, 0, 'h'},
{ "compact", no_argument, 0, 'c'},
{ "type", required_argument, 0, 't'},
{ "relaxed", no_argument, 0, 'r'},
{ "version", no_argument, 0, 'v'},
{ "help", no_argument, 0, 'h'},
{ 0, 0, 0, 0}
};
const char* arg_format = "ct:rh";
const char* arg_format = "ct:rvh";

while (1) {
int c = getopt_long (argc, argv, arg_format, long_options, NULL);
Expand All @@ -101,6 +103,10 @@ static void parse_args (int argc, char* argv[], appargs_t& args)
case 'r':
args.relaxed = true;
break;
case 'v':
std::cout << prog_name << ' ' << PACKAGE_VERSION << std::endl;
exit (0);
break;
case 'h':
print_usage_and_exit (std::cout, 0);
break;
Expand Down
3 changes: 3 additions & 0 deletions utils/ujson-get.man
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Require the value to be of a specific type. TYPE is one of the following: boolea
.B -r, --relaxed
Parse the JSON document in relaxed mode.
.TP
.B -v, --version
Print version and exit.
.TP
.B -h, --help
Print help and exit.

Expand Down
10 changes: 8 additions & 2 deletions utils/ujson-patch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Dan Arrhenius <dan@ultramarin.se>
* Copyright (C) 2021,2022 Dan Arrhenius <dan@ultramarin.se>
*
* This file is part of ujson.
*
Expand Down Expand Up @@ -68,6 +68,7 @@ static void print_usage_and_exit (std::ostream& out, int exit_code)
out << " patch operations of type 'test', nothing is written to standard output." << endl;
out << " If the patch definition contains operations other than 'test', the resulting JSON" << endl;
out << " document is still printed to standard output." << endl;
out << " -v, --version Print version and exit." << endl;
out << " -h, --help Print this help message and exit." << endl;
out << endl;
out << "" << endl;
Expand All @@ -83,10 +84,11 @@ static void parse_args (int argc, char* argv[], appargs_t& args)
{ "compact", no_argument, 0, 'c'},
{ "relaxed", no_argument, 0, 'r'},
{ "quiet", no_argument, 0, 'q'},
{ "version", no_argument, 0, 'v'},
{ "help", no_argument, 0, 'h'},
{ 0, 0, 0, 0}
};
const char* arg_format = "crqh";
const char* arg_format = "crqvh";

while (1) {
int c = getopt_long (argc, argv, arg_format, long_options, NULL);
Expand All @@ -102,6 +104,10 @@ static void parse_args (int argc, char* argv[], appargs_t& args)
case 'q':
args.quiet = true;
break;
case 'v':
std::cout << prog_name << ' ' << PACKAGE_VERSION << std::endl;
exit (0);
break;
case 'h':
print_usage_and_exit (std::cout, 0);
break;
Expand Down
3 changes: 3 additions & 0 deletions utils/ujson-patch.man
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Parse JSON input files in relaxed mode.
.B -q, --quiet
No errors are written to standard error. On errors, of failed patch test operations, the application exits with an error code. If the patch definition only contains patch operations of type 'test', nothing is written to standard output. If the patch definition contains operations other than 'test', the resulting JSON document is still printed to standard output.
.TP
.B -v, --version
Print version and exit.
.TP
.B -h, --help
Print help and exit.

Expand Down
8 changes: 7 additions & 1 deletion utils/ujson-print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static void print_usage_and_exit (std::ostream& out, int exit_code)
out << " Object member names are printed without enclosing double quotes" << endl;
out << " when the names are in the following format: [_a-zA-Z][_a-zA-Z0-9]*" << endl;
out << " -t, --parse-strict Parse the JSON document in strict mode." << endl;
out << " -v, --version Print version and exit." << endl;
out << " -h, --help Print this help message and exit." << endl;
out << endl;
exit (exit_code);
Expand All @@ -84,10 +85,11 @@ static void parse_args (int argc, char* argv[], appargs_t& args)
{ "sort", no_argument, 0, 's'},
{ "relaxed", no_argument, 0, 'r'},
{ "parse-strict", no_argument, 0, 't'},
{ "version", no_argument, 0, 'v'},
{ "help", no_argument, 0, 'h'},
{ 0, 0, 0, 0}
};
const char* arg_format = "cesrth";
const char* arg_format = "cesrtvh";

while (1) {
int c = getopt_long (argc, argv, arg_format, long_options, nullptr);
Expand All @@ -109,6 +111,10 @@ static void parse_args (int argc, char* argv[], appargs_t& args)
case 't':
args.parse_strict = true;
break;
case 'v':
std::cout << prog_name << ' ' << PACKAGE_VERSION << std::endl;
exit (0);
break;
case 'h':
print_usage_and_exit (std::cout, 0);
break;
Expand Down
3 changes: 3 additions & 0 deletions utils/ujson-print.man
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Print the JSON document in relaxed form. Numbers that are infinite or NaN are pr
.B -t, --parse-strict
Parse the JSON document in strict mode.
.TP
.B -v, --version
Print version and exit.
.TP
.B -h, --help
Print help and exit.

Expand Down
34 changes: 20 additions & 14 deletions utils/ujson-verify.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Dan Arrhenius <dan@ultramarin.se>
* Copyright (C) 2021,2022 Dan Arrhenius <dan@ultramarin.se>
*
* This file is part of ujson.
*
Expand Down Expand Up @@ -60,14 +60,15 @@ static void print_usage_and_exit (std::ostream& out, int exit_code)
<< "Usage: " << prog_name << " [OPTIONS] [FILE...]" << endl
<< endl
<< "Options:" <<endl
<< " -r, --relax Relaxed parsing, don't use strict mode when parsing." << endl
<< " -s, --schema=FILE Validate the JSON document with a schema file." << endl
<< " This option can be used multiple times." << endl
<< " The first schema will be used to validate the JSON document." << endl
<< " All schemas added after the first are schemas" << endl
<< " that can be referenced by the first schema." << endl
<< " -q, --quiet Silent mode, don't write anything to standard output." << endl
<< " -h, --help Print this help message and exit." << endl
<< " -r, --relax Relaxed parsing, don't use strict mode when parsing." << endl
<< " -s, --schema=FILE Validate the JSON document with a schema file." << endl
<< " This option can be used multiple times." << endl
<< " The first schema will be used to validate the JSON document." << endl
<< " All schemas added after the first are schemas" << endl
<< " that can be referenced by the first schema." << endl
<< " -q, --quiet Silent mode, don't write anything to standard output." << endl
<< " -v, --version Print version and exit." << endl
<< " -h, --help Print this help message and exit." << endl
<< endl;
exit (exit_code);
}
Expand All @@ -78,13 +79,14 @@ static void print_usage_and_exit (std::ostream& out, int exit_code)
static void parse_args (int argc, char* argv[], appargs_t& args)
{
struct option long_options[] = {
{ "relax", no_argument, 0, 'r'},
{ "schema", required_argument, 0, 's'},
{ "quiet", no_argument, 0, 'q'},
{ "help", no_argument, 0, 'h'},
{ "relax", no_argument, 0, 'r'},
{ "schema", required_argument, 0, 's'},
{ "quiet", no_argument, 0, 'q'},
{ "version", no_argument, 0, 'v'},
{ "help", no_argument, 0, 'h'},
{ 0, 0, 0, 0}
};
const char* arg_format = "rs:qh";
const char* arg_format = "rs:qvh";

while (1) {
int c = getopt_long (argc, argv, arg_format, long_options, NULL);
Expand All @@ -103,6 +105,10 @@ static void parse_args (int argc, char* argv[], appargs_t& args)
case 'q':
args.quiet = true;
break;
case 'v':
std::cout << prog_name << ' ' << PACKAGE_VERSION << std::endl;
exit (0);
break;
case 'h':
print_usage_and_exit (std::cout, 0);
break;
Expand Down
14 changes: 10 additions & 4 deletions utils/ujson-verify.man
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Validate the JSON document with a schema file. This option can be used multiple
.B -q, --quiet
Silent mode, don't write anything to standard output.
.TP
.B -v, --version
Print version and exit.
.TP
.B -h, --help
Print help and exit.

Expand All @@ -39,13 +42,13 @@ The following is allowed in JSON documents when relaxed format is used:
.nf
- C-style comments.
- String values can be split up into more than one string separated by whitespace or comments.
- When parsing a number, the identifiers nan and (+/-)inf/infinite are allowed.
- When parsing a number, the special values nan and (+/-)inf/infinite are allowed.
- Object definitions are allowed to end with a separator(,).
- Array items are allowed to end with a separator(,).
- In object definitions, a member name can be an identifier instead of a string.
An identifier is a name in the following format: [_a-zA-Z][_a-zA-Z0-9]*
Exceptions are: nan, inf, and infinite (case insensitive).
Those names are reserved for numbers and are not allowed to be used as identifiers.
An identifier is a name with the following format: [_a-zA-Z][_a-zA-Z0-9]*
Exceptions are: true, false, null, nan, inf, and infinite (case insensitive).
Those names are reserved and are not allowed to be used as identifiers (i.e. without enclosing double quotes).

.PP
Example of a JSON document that is allowed in relaxed mode:
Expand All @@ -62,6 +65,9 @@ Example of a JSON document that is allowed in relaxed mode:
not_a_number: NaN,
"normal_member_name": "Another string",
// The following object member name must be enclosed by double quotes
"null": 0,
long_string: "This is a string value on " // This can be used to
"more than one line that, " // make it more readable.
"when parsed, will be one "
Expand Down

0 comments on commit a29448d

Please sign in to comment.