aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-20 13:25:54 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-20 15:16:25 +0200
commitdc8df962d8f0d93595a4e036bb29bc3498abc35f (patch)
treedc0d45d7fe2d1e1a29b1b5d84e9e5c73ce72d51a
parent907df2c823710319e53c0ba6583a1ede4ee5413d (diff)
downloadqpdf-dc8df962d8f0d93595a4e036bb29bc3498abc35f.tar.zst
Make version default to latest for --json-output (like --json)
-rw-r--r--include/qpdf/auto_job_c_main.hh3
-rw-r--r--job.sums12
-rw-r--r--job.yml2
-rw-r--r--libqpdf/QPDFJob_config.cc12
-rw-r--r--libqpdf/qpdf/auto_job_help.hh11
-rw-r--r--libqpdf/qpdf/auto_job_init.hh2
-rw-r--r--libqpdf/qpdf/auto_job_json_init.hh2
-rw-r--r--manual/cli.rst20
-rw-r--r--qpdf/qtest/qpdf-json.test4
9 files changed, 37 insertions, 31 deletions
diff --git a/include/qpdf/auto_job_c_main.hh b/include/qpdf/auto_job_c_main.hh
index 0b2b559d..90927ded 100644
--- a/include/qpdf/auto_job_c_main.hh
+++ b/include/qpdf/auto_job_c_main.hh
@@ -77,7 +77,6 @@ QPDF_DLL Config* compressStreams(std::string const& parameter);
QPDF_DLL Config* decodeLevel(std::string const& parameter);
QPDF_DLL Config* flattenAnnotations(std::string const& parameter);
QPDF_DLL Config* jsonKey(std::string const& parameter);
-QPDF_DLL Config* jsonOutput(std::string const& parameter);
QPDF_DLL Config* jsonStreamData(std::string const& parameter);
QPDF_DLL Config* keepFilesOpen(std::string const& parameter);
QPDF_DLL Config* normalizeContent(std::string const& parameter);
@@ -87,3 +86,5 @@ QPDF_DLL Config* removeUnreferencedResources(std::string const& parameter);
QPDF_DLL Config* streamData(std::string const& parameter);
QPDF_DLL Config* json(std::string const& parameter);
QPDF_DLL Config* json();
+QPDF_DLL Config* jsonOutput(std::string const& parameter);
+QPDF_DLL Config* jsonOutput();
diff --git a/job.sums b/job.sums
index 5cb04368..63801a83 100644
--- a/job.sums
+++ b/job.sums
@@ -3,15 +3,15 @@ generate_auto_job 0514289f2deb3bf7c1a6e85ef7d99ad120321ef5a6fe49d76c5274c6a658d3
include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4
include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42
include/qpdf/auto_job_c_enc.hh 28446f3c32153a52afa239ea40503e6cc8ac2c026813526a349e0cd4ae17ddd5
-include/qpdf/auto_job_c_main.hh c21395ba79b98b3054f6d73266285d216b77568ea55ca7149d3e6a157604d682
+include/qpdf/auto_job_c_main.hh cdba1ae6ea5525a585d10a3dd95b7996d62b17de4211fe658b78d9d463b0f313
include/qpdf/auto_job_c_pages.hh b3cc0f21029f6d89efa043dcdbfa183cb59325b6506001c18911614fe8e568ec
include/qpdf/auto_job_c_uo.hh ae21b69a1efa9333050f4833d465f6daff87e5b38e5106e49bbef5d4132e4ed1
-job.yml feae32412cc75f84fb9ff7521121466f9582e85547f45613c3a7083a929f01e6
+job.yml 3b2b3c6f92b48f6c76109711cbfdd74669fa31a80cd17379548b09f8e76be05d
libqpdf/qpdf/auto_job_decl.hh 74df4d7fdbdf51ecd0d58ce1e9844bb5525b9adac5a45f7c9a787ecdda2868df
-libqpdf/qpdf/auto_job_help.hh 5ca1d2b73f6a70f1ef47896b49553ae8ded4a6459bbb1f6697947e2cc598d799
-libqpdf/qpdf/auto_job_init.hh 3acc779ff96bde839c8c95a844145df830c53ee58fbf61b8ce056a1751bc11f2
+libqpdf/qpdf/auto_job_help.hh 3ea60a392421150bec5e95ddaad31a82fba1d65c2686d5dfddc920aba1bf5552
+libqpdf/qpdf/auto_job_init.hh 7ea8e0641dc26fdfba6e283e14dbbff0c016654e174cdace8054f8bef53750fd
libqpdf/qpdf/auto_job_json_decl.hh 06caa46eaf71db8a50c046f91866baa8087745a9474319fb7c86d92634cc8297
-libqpdf/qpdf/auto_job_json_init.hh 0441fd710ded1512a84976b542910fec16e8b9ab665e5efb5b37c5a29fd8654f
+libqpdf/qpdf/auto_job_json_init.hh 5f6b53e3c81d4b54ce5c4cf9c3f52d0c02f987c53bf8841c0280367bad23e335
libqpdf/qpdf/auto_job_schema.hh 9d543cd4a43eafffc2c4b8a6fee29e399c271c52cb6f7d417ae5497b3c1127dc
manual/_ext/qpdf.py 6add6321666031d55ed4aedf7c00e5662bba856dfcd66ccb526563bffefbb580
-manual/cli.rst 3d133669f2b1f845bbc09e51e5b6fff6dd8803282b71aff0db2c55878b1ec508
+manual/cli.rst 174cf35e3ce5452701d74c87570604e19587cc41bfa3f6d239b62c2989720bdf
diff --git a/job.yml b/job.yml
index 20e87ad7..12d2bd44 100644
--- a/job.yml
+++ b/job.yml
@@ -171,7 +171,6 @@ options:
decode-level: decode_level
flatten-annotations: flatten
json-key: json_key
- json-output: json_output
json-stream-data: json_stream_data
keep-files-open: yn
normalize-content: yn
@@ -181,6 +180,7 @@ options:
stream-data: stream_data
optional_choices:
json: json_version
+ json-output: json_output
- table: pages
config: c_pages
prefix: Pages
diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc
index ecdeafe3..6b72103b 100644
--- a/libqpdf/QPDFJob_config.cc
+++ b/libqpdf/QPDFJob_config.cc
@@ -295,14 +295,14 @@ QPDFJob::Config::jsonInput()
QPDFJob::Config*
QPDFJob::Config::jsonOutput(std::string const& parameter)
{
- std::string v = parameter;
- if (parameter == "latest") {
- v = "2";
+ if (parameter.empty() || (parameter == "latest")) {
+ o.m->json_output = JSON::LATEST;
+ } else {
+ o.m->json_output = QUtil::string_to_int(parameter.c_str());
}
- if (v != "2") {
- usage("only version 2 is supported for --json-output");
+ if ((o.m->json_output < 2) || (o.m->json_output > JSON::LATEST)) {
+ usage(std::string("unsupported json output version ") + parameter);
}
- o.m->json_output = QUtil::string_to_int(v.c_str());
if (!o.m->json_stream_data_set) {
// No need to set json_stream_data_set -- that indicates
// explicit use of --json-stream-data.
diff --git a/libqpdf/qpdf/auto_job_help.hh b/libqpdf/qpdf/auto_job_help.hh
index 7d88155b..e4bab551 100644
--- a/libqpdf/qpdf/auto_job_help.hh
+++ b/libqpdf/qpdf/auto_job_help.hh
@@ -795,8 +795,8 @@ ap.addOptionHelp("--json", "json", "show file in JSON format", R"(--json[=versio
Generate a JSON representation of the file. This is described in
depth in the JSON section of the manual. "version" may be a
-specific version or "latest". Run qpdf --json-help for a
-description of the generated JSON object.
+specific version or "latest" (the default). Run qpdf --json-help
+for a description of the generated JSON object.
)");
ap.addOptionHelp("--json-help", "json", "show format of JSON output", R"(Describe the format of the JSON output by writing to standard
output a JSON object with the same keys and with values
@@ -832,11 +832,12 @@ name as the prefix for stream data files. Whatever is given here
will be appended with -nnn to create the name of the file that
will contain the data for the stream stream in object nnn.
)");
-ap.addOptionHelp("--json-output", "json", "serialize to JSON", R"(--json-output=version
+ap.addOptionHelp("--json-output", "json", "serialize to JSON", R"(--json-output[=version]
The output file will be qpdf JSON format at the given version.
-Only version 2 is supported. See also --json-stream-data
-and --json-stream-prefix
+"version" may be a specific version or "latest" (the default).
+Version 1 is not supported. See also --json-stream-data
+and --json-stream-prefix.
)");
ap.addOptionHelp("--json-input", "json", "input file is qpdf JSON", R"(Treat the input file as a JSON file in qpdf JSON format as
written by qpdf --json-output. See the "QPDF JSON Format"
diff --git a/libqpdf/qpdf/auto_job_init.hh b/libqpdf/qpdf/auto_job_init.hh
index f582c6ec..c76a0b6a 100644
--- a/libqpdf/qpdf/auto_job_init.hh
+++ b/libqpdf/qpdf/auto_job_init.hh
@@ -112,7 +112,6 @@ this->ap.addChoices("compress-streams", [this](std::string const& x){c_main->com
this->ap.addChoices("decode-level", [this](std::string const& x){c_main->decodeLevel(x);}, true, decode_level_choices);
this->ap.addChoices("flatten-annotations", [this](std::string const& x){c_main->flattenAnnotations(x);}, true, flatten_choices);
this->ap.addChoices("json-key", [this](std::string const& x){c_main->jsonKey(x);}, true, json_key_choices);
-this->ap.addChoices("json-output", [this](std::string const& x){c_main->jsonOutput(x);}, true, json_output_choices);
this->ap.addChoices("json-stream-data", [this](std::string const& x){c_main->jsonStreamData(x);}, true, json_stream_data_choices);
this->ap.addChoices("keep-files-open", [this](std::string const& x){c_main->keepFilesOpen(x);}, true, yn_choices);
this->ap.addChoices("normalize-content", [this](std::string const& x){c_main->normalizeContent(x);}, true, yn_choices);
@@ -121,6 +120,7 @@ this->ap.addChoices("password-mode", [this](std::string const& x){c_main->passwo
this->ap.addChoices("remove-unreferenced-resources", [this](std::string const& x){c_main->removeUnreferencedResources(x);}, true, remove_unref_choices);
this->ap.addChoices("stream-data", [this](std::string const& x){c_main->streamData(x);}, true, stream_data_choices);
this->ap.addChoices("json", [this](std::string const& x){c_main->json(x);}, false, json_version_choices);
+this->ap.addChoices("json-output", [this](std::string const& x){c_main->jsonOutput(x);}, false, json_output_choices);
this->ap.registerOptionTable("pages", b(&ArgParser::argEndPages));
this->ap.addPositional(p(&ArgParser::argPagesPositional));
this->ap.addRequiredParameter("password", p(&ArgParser::argPagesPassword), "password");
diff --git a/libqpdf/qpdf/auto_job_json_init.hh b/libqpdf/qpdf/auto_job_json_init.hh
index 125250e6..168d5676 100644
--- a/libqpdf/qpdf/auto_job_json_init.hh
+++ b/libqpdf/qpdf/auto_job_json_init.hh
@@ -107,7 +107,7 @@ pushKey("splitPages");
addParameter([this](std::string const& p) { c_main->splitPages(p); });
popHandler(); // key: splitPages
pushKey("jsonOutput");
-addChoices(json_output_choices, true, [this](std::string const& p) { c_main->jsonOutput(p); });
+addChoices(json_output_choices, false, [this](std::string const& p) { c_main->jsonOutput(p); });
popHandler(); // key: jsonOutput
pushKey("encrypt");
beginDict(bindJSON(&Handlers::beginEncrypt), bindBare(&Handlers::endEncrypt)); // .encrypt
diff --git a/manual/cli.rst b/manual/cli.rst
index 6cfae38b..2bc829df 100644
--- a/manual/cli.rst
+++ b/manual/cli.rst
@@ -3158,8 +3158,8 @@ Related Options
Generate a JSON representation of the file. This is described in
depth in the JSON section of the manual. "version" may be a
- specific version or "latest". Run qpdf --json-help for a
- description of the generated JSON object.
+ specific version or "latest" (the default). Run qpdf --json-help
+ for a description of the generated JSON object.
Generate a JSON representation of the file. This is described in
depth in :ref:`json`. The version parameter can be used to specify
@@ -3258,17 +3258,19 @@ Related Options
data for the stream stream in object :samp:`{nnn}`. This
option only applies when used with :qpdf:ref:`--json-output`.
-.. qpdf:option:: --json-output=version
+.. qpdf:option:: --json-output[=version]
.. help: serialize to JSON
The output file will be qpdf JSON format at the given version.
- Only version 2 is supported. See also --json-stream-data
- and --json-stream-prefix
-
- The output file will be qpdf JSON format at the given version. Only
- version 2 is supported. See also :qpdf:ref:`--json-stream-data` and
- :qpdf:ref:`--json-stream-prefix`.
+ "version" may be a specific version or "latest" (the default).
+ Version 1 is not supported. See also --json-stream-data
+ and --json-stream-prefix.
+
+ The output file will be qpdf JSON format at the given version.
+ ``version`` may be a specific version or ``latest`` (the default).
+ Version 1 is not supported. See also :qpdf:ref:`--json-stream-data`
+ and :qpdf:ref:`--json-stream-prefix`.
.. qpdf:option:: --json-input
diff --git a/qpdf/qtest/qpdf-json.test b/qpdf/qtest/qpdf-json.test
index 3ab581e7..9e92e27d 100644
--- a/qpdf/qtest/qpdf-json.test
+++ b/qpdf/qtest/qpdf-json.test
@@ -67,15 +67,17 @@ foreach my $i (@goodfiles)
if (ref($i) eq 'ARRAY') {
($f, $xargs) = @$i;
}
+ # explicit "latest" as --json-output version
$td->runtest("good: $f -> JSON",
{$td->COMMAND => "qpdf $xargs --decode-level=none" .
" --json-output=latest $f a.json"},
{$td->STRING => "", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
+ # default --json-output version
$td->runtest("good: $f JSON -> JSON",
{$td->COMMAND =>
"qpdf --decode-level=none" .
- " --json-input --json-output=latest a.json b.json"},
+ " --json-input --json-output a.json b.json"},
{$td->STRING => "", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("good: $f JSON -> QDF",