Commit dc8df962d8f0d93595a4e036bb29bc3498abc35f

Authored by Jay Berkenbilt
1 parent 907df2c8

Make version default to latest for --json-output (like --json)

include/qpdf/auto_job_c_main.hh
@@ -77,7 +77,6 @@ QPDF_DLL Config* compressStreams(std::string const& parameter); @@ -77,7 +77,6 @@ QPDF_DLL Config* compressStreams(std::string const& parameter);
77 QPDF_DLL Config* decodeLevel(std::string const& parameter); 77 QPDF_DLL Config* decodeLevel(std::string const& parameter);
78 QPDF_DLL Config* flattenAnnotations(std::string const& parameter); 78 QPDF_DLL Config* flattenAnnotations(std::string const& parameter);
79 QPDF_DLL Config* jsonKey(std::string const& parameter); 79 QPDF_DLL Config* jsonKey(std::string const& parameter);
80 -QPDF_DLL Config* jsonOutput(std::string const& parameter);  
81 QPDF_DLL Config* jsonStreamData(std::string const& parameter); 80 QPDF_DLL Config* jsonStreamData(std::string const& parameter);
82 QPDF_DLL Config* keepFilesOpen(std::string const& parameter); 81 QPDF_DLL Config* keepFilesOpen(std::string const& parameter);
83 QPDF_DLL Config* normalizeContent(std::string const& parameter); 82 QPDF_DLL Config* normalizeContent(std::string const& parameter);
@@ -87,3 +86,5 @@ QPDF_DLL Config* removeUnreferencedResources(std::string const& parameter); @@ -87,3 +86,5 @@ QPDF_DLL Config* removeUnreferencedResources(std::string const& parameter);
87 QPDF_DLL Config* streamData(std::string const& parameter); 86 QPDF_DLL Config* streamData(std::string const& parameter);
88 QPDF_DLL Config* json(std::string const& parameter); 87 QPDF_DLL Config* json(std::string const& parameter);
89 QPDF_DLL Config* json(); 88 QPDF_DLL Config* json();
  89 +QPDF_DLL Config* jsonOutput(std::string const& parameter);
  90 +QPDF_DLL Config* jsonOutput();
job.sums
@@ -3,15 +3,15 @@ generate_auto_job 0514289f2deb3bf7c1a6e85ef7d99ad120321ef5a6fe49d76c5274c6a658d3 @@ -3,15 +3,15 @@ generate_auto_job 0514289f2deb3bf7c1a6e85ef7d99ad120321ef5a6fe49d76c5274c6a658d3
3 include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4 3 include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4
4 include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42 4 include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42
5 include/qpdf/auto_job_c_enc.hh 28446f3c32153a52afa239ea40503e6cc8ac2c026813526a349e0cd4ae17ddd5 5 include/qpdf/auto_job_c_enc.hh 28446f3c32153a52afa239ea40503e6cc8ac2c026813526a349e0cd4ae17ddd5
6 -include/qpdf/auto_job_c_main.hh c21395ba79b98b3054f6d73266285d216b77568ea55ca7149d3e6a157604d682 6 +include/qpdf/auto_job_c_main.hh cdba1ae6ea5525a585d10a3dd95b7996d62b17de4211fe658b78d9d463b0f313
7 include/qpdf/auto_job_c_pages.hh b3cc0f21029f6d89efa043dcdbfa183cb59325b6506001c18911614fe8e568ec 7 include/qpdf/auto_job_c_pages.hh b3cc0f21029f6d89efa043dcdbfa183cb59325b6506001c18911614fe8e568ec
8 include/qpdf/auto_job_c_uo.hh ae21b69a1efa9333050f4833d465f6daff87e5b38e5106e49bbef5d4132e4ed1 8 include/qpdf/auto_job_c_uo.hh ae21b69a1efa9333050f4833d465f6daff87e5b38e5106e49bbef5d4132e4ed1
9 -job.yml feae32412cc75f84fb9ff7521121466f9582e85547f45613c3a7083a929f01e6 9 +job.yml 3b2b3c6f92b48f6c76109711cbfdd74669fa31a80cd17379548b09f8e76be05d
10 libqpdf/qpdf/auto_job_decl.hh 74df4d7fdbdf51ecd0d58ce1e9844bb5525b9adac5a45f7c9a787ecdda2868df 10 libqpdf/qpdf/auto_job_decl.hh 74df4d7fdbdf51ecd0d58ce1e9844bb5525b9adac5a45f7c9a787ecdda2868df
11 -libqpdf/qpdf/auto_job_help.hh 5ca1d2b73f6a70f1ef47896b49553ae8ded4a6459bbb1f6697947e2cc598d799  
12 -libqpdf/qpdf/auto_job_init.hh 3acc779ff96bde839c8c95a844145df830c53ee58fbf61b8ce056a1751bc11f2 11 +libqpdf/qpdf/auto_job_help.hh 3ea60a392421150bec5e95ddaad31a82fba1d65c2686d5dfddc920aba1bf5552
  12 +libqpdf/qpdf/auto_job_init.hh 7ea8e0641dc26fdfba6e283e14dbbff0c016654e174cdace8054f8bef53750fd
13 libqpdf/qpdf/auto_job_json_decl.hh 06caa46eaf71db8a50c046f91866baa8087745a9474319fb7c86d92634cc8297 13 libqpdf/qpdf/auto_job_json_decl.hh 06caa46eaf71db8a50c046f91866baa8087745a9474319fb7c86d92634cc8297
14 -libqpdf/qpdf/auto_job_json_init.hh 0441fd710ded1512a84976b542910fec16e8b9ab665e5efb5b37c5a29fd8654f 14 +libqpdf/qpdf/auto_job_json_init.hh 5f6b53e3c81d4b54ce5c4cf9c3f52d0c02f987c53bf8841c0280367bad23e335
15 libqpdf/qpdf/auto_job_schema.hh 9d543cd4a43eafffc2c4b8a6fee29e399c271c52cb6f7d417ae5497b3c1127dc 15 libqpdf/qpdf/auto_job_schema.hh 9d543cd4a43eafffc2c4b8a6fee29e399c271c52cb6f7d417ae5497b3c1127dc
16 manual/_ext/qpdf.py 6add6321666031d55ed4aedf7c00e5662bba856dfcd66ccb526563bffefbb580 16 manual/_ext/qpdf.py 6add6321666031d55ed4aedf7c00e5662bba856dfcd66ccb526563bffefbb580
17 -manual/cli.rst 3d133669f2b1f845bbc09e51e5b6fff6dd8803282b71aff0db2c55878b1ec508 17 +manual/cli.rst 174cf35e3ce5452701d74c87570604e19587cc41bfa3f6d239b62c2989720bdf
@@ -171,7 +171,6 @@ options: @@ -171,7 +171,6 @@ options:
171 decode-level: decode_level 171 decode-level: decode_level
172 flatten-annotations: flatten 172 flatten-annotations: flatten
173 json-key: json_key 173 json-key: json_key
174 - json-output: json_output  
175 json-stream-data: json_stream_data 174 json-stream-data: json_stream_data
176 keep-files-open: yn 175 keep-files-open: yn
177 normalize-content: yn 176 normalize-content: yn
@@ -181,6 +180,7 @@ options: @@ -181,6 +180,7 @@ options:
181 stream-data: stream_data 180 stream-data: stream_data
182 optional_choices: 181 optional_choices:
183 json: json_version 182 json: json_version
  183 + json-output: json_output
184 - table: pages 184 - table: pages
185 config: c_pages 185 config: c_pages
186 prefix: Pages 186 prefix: Pages
libqpdf/QPDFJob_config.cc
@@ -295,14 +295,14 @@ QPDFJob::Config::jsonInput() @@ -295,14 +295,14 @@ QPDFJob::Config::jsonInput()
295 QPDFJob::Config* 295 QPDFJob::Config*
296 QPDFJob::Config::jsonOutput(std::string const& parameter) 296 QPDFJob::Config::jsonOutput(std::string const& parameter)
297 { 297 {
298 - std::string v = parameter;  
299 - if (parameter == "latest") {  
300 - v = "2"; 298 + if (parameter.empty() || (parameter == "latest")) {
  299 + o.m->json_output = JSON::LATEST;
  300 + } else {
  301 + o.m->json_output = QUtil::string_to_int(parameter.c_str());
301 } 302 }
302 - if (v != "2") {  
303 - usage("only version 2 is supported for --json-output"); 303 + if ((o.m->json_output < 2) || (o.m->json_output > JSON::LATEST)) {
  304 + usage(std::string("unsupported json output version ") + parameter);
304 } 305 }
305 - o.m->json_output = QUtil::string_to_int(v.c_str());  
306 if (!o.m->json_stream_data_set) { 306 if (!o.m->json_stream_data_set) {
307 // No need to set json_stream_data_set -- that indicates 307 // No need to set json_stream_data_set -- that indicates
308 // explicit use of --json-stream-data. 308 // explicit use of --json-stream-data.
libqpdf/qpdf/auto_job_help.hh
@@ -795,8 +795,8 @@ ap.addOptionHelp(&quot;--json&quot;, &quot;json&quot;, &quot;show file in JSON format&quot;, R&quot;(--json[=versio @@ -795,8 +795,8 @@ ap.addOptionHelp(&quot;--json&quot;, &quot;json&quot;, &quot;show file in JSON format&quot;, R&quot;(--json[=versio
795 795
796 Generate a JSON representation of the file. This is described in 796 Generate a JSON representation of the file. This is described in
797 depth in the JSON section of the manual. "version" may be a 797 depth in the JSON section of the manual. "version" may be a
798 -specific version or "latest". Run qpdf --json-help for a  
799 -description of the generated JSON object. 798 +specific version or "latest" (the default). Run qpdf --json-help
  799 +for a description of the generated JSON object.
800 )"); 800 )");
801 ap.addOptionHelp("--json-help", "json", "show format of JSON output", R"(Describe the format of the JSON output by writing to standard 801 ap.addOptionHelp("--json-help", "json", "show format of JSON output", R"(Describe the format of the JSON output by writing to standard
802 output a JSON object with the same keys and with values 802 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 @@ -832,11 +832,12 @@ name as the prefix for stream data files. Whatever is given here
832 will be appended with -nnn to create the name of the file that 832 will be appended with -nnn to create the name of the file that
833 will contain the data for the stream stream in object nnn. 833 will contain the data for the stream stream in object nnn.
834 )"); 834 )");
835 -ap.addOptionHelp("--json-output", "json", "serialize to JSON", R"(--json-output=version 835 +ap.addOptionHelp("--json-output", "json", "serialize to JSON", R"(--json-output[=version]
836 836
837 The output file will be qpdf JSON format at the given version. 837 The output file will be qpdf JSON format at the given version.
838 -Only version 2 is supported. See also --json-stream-data  
839 -and --json-stream-prefix 838 +"version" may be a specific version or "latest" (the default).
  839 +Version 1 is not supported. See also --json-stream-data
  840 +and --json-stream-prefix.
840 )"); 841 )");
841 ap.addOptionHelp("--json-input", "json", "input file is qpdf JSON", R"(Treat the input file as a JSON file in qpdf JSON format as 842 ap.addOptionHelp("--json-input", "json", "input file is qpdf JSON", R"(Treat the input file as a JSON file in qpdf JSON format as
842 written by qpdf --json-output. See the "QPDF JSON Format" 843 written by qpdf --json-output. See the "QPDF JSON Format"
libqpdf/qpdf/auto_job_init.hh
@@ -112,7 +112,6 @@ this-&gt;ap.addChoices(&quot;compress-streams&quot;, [this](std::string const&amp; x){c_main-&gt;com @@ -112,7 +112,6 @@ this-&gt;ap.addChoices(&quot;compress-streams&quot;, [this](std::string const&amp; x){c_main-&gt;com
112 this->ap.addChoices("decode-level", [this](std::string const& x){c_main->decodeLevel(x);}, true, decode_level_choices); 112 this->ap.addChoices("decode-level", [this](std::string const& x){c_main->decodeLevel(x);}, true, decode_level_choices);
113 this->ap.addChoices("flatten-annotations", [this](std::string const& x){c_main->flattenAnnotations(x);}, true, flatten_choices); 113 this->ap.addChoices("flatten-annotations", [this](std::string const& x){c_main->flattenAnnotations(x);}, true, flatten_choices);
114 this->ap.addChoices("json-key", [this](std::string const& x){c_main->jsonKey(x);}, true, json_key_choices); 114 this->ap.addChoices("json-key", [this](std::string const& x){c_main->jsonKey(x);}, true, json_key_choices);
115 -this->ap.addChoices("json-output", [this](std::string const& x){c_main->jsonOutput(x);}, true, json_output_choices);  
116 this->ap.addChoices("json-stream-data", [this](std::string const& x){c_main->jsonStreamData(x);}, true, json_stream_data_choices); 115 this->ap.addChoices("json-stream-data", [this](std::string const& x){c_main->jsonStreamData(x);}, true, json_stream_data_choices);
117 this->ap.addChoices("keep-files-open", [this](std::string const& x){c_main->keepFilesOpen(x);}, true, yn_choices); 116 this->ap.addChoices("keep-files-open", [this](std::string const& x){c_main->keepFilesOpen(x);}, true, yn_choices);
118 this->ap.addChoices("normalize-content", [this](std::string const& x){c_main->normalizeContent(x);}, true, yn_choices); 117 this->ap.addChoices("normalize-content", [this](std::string const& x){c_main->normalizeContent(x);}, true, yn_choices);
@@ -121,6 +120,7 @@ this-&gt;ap.addChoices(&quot;password-mode&quot;, [this](std::string const&amp; x){c_main-&gt;passwo @@ -121,6 +120,7 @@ this-&gt;ap.addChoices(&quot;password-mode&quot;, [this](std::string const&amp; x){c_main-&gt;passwo
121 this->ap.addChoices("remove-unreferenced-resources", [this](std::string const& x){c_main->removeUnreferencedResources(x);}, true, remove_unref_choices); 120 this->ap.addChoices("remove-unreferenced-resources", [this](std::string const& x){c_main->removeUnreferencedResources(x);}, true, remove_unref_choices);
122 this->ap.addChoices("stream-data", [this](std::string const& x){c_main->streamData(x);}, true, stream_data_choices); 121 this->ap.addChoices("stream-data", [this](std::string const& x){c_main->streamData(x);}, true, stream_data_choices);
123 this->ap.addChoices("json", [this](std::string const& x){c_main->json(x);}, false, json_version_choices); 122 this->ap.addChoices("json", [this](std::string const& x){c_main->json(x);}, false, json_version_choices);
  123 +this->ap.addChoices("json-output", [this](std::string const& x){c_main->jsonOutput(x);}, false, json_output_choices);
124 this->ap.registerOptionTable("pages", b(&ArgParser::argEndPages)); 124 this->ap.registerOptionTable("pages", b(&ArgParser::argEndPages));
125 this->ap.addPositional(p(&ArgParser::argPagesPositional)); 125 this->ap.addPositional(p(&ArgParser::argPagesPositional));
126 this->ap.addRequiredParameter("password", p(&ArgParser::argPagesPassword), "password"); 126 this->ap.addRequiredParameter("password", p(&ArgParser::argPagesPassword), "password");
libqpdf/qpdf/auto_job_json_init.hh
@@ -107,7 +107,7 @@ pushKey(&quot;splitPages&quot;); @@ -107,7 +107,7 @@ pushKey(&quot;splitPages&quot;);
107 addParameter([this](std::string const& p) { c_main->splitPages(p); }); 107 addParameter([this](std::string const& p) { c_main->splitPages(p); });
108 popHandler(); // key: splitPages 108 popHandler(); // key: splitPages
109 pushKey("jsonOutput"); 109 pushKey("jsonOutput");
110 -addChoices(json_output_choices, true, [this](std::string const& p) { c_main->jsonOutput(p); }); 110 +addChoices(json_output_choices, false, [this](std::string const& p) { c_main->jsonOutput(p); });
111 popHandler(); // key: jsonOutput 111 popHandler(); // key: jsonOutput
112 pushKey("encrypt"); 112 pushKey("encrypt");
113 beginDict(bindJSON(&Handlers::beginEncrypt), bindBare(&Handlers::endEncrypt)); // .encrypt 113 beginDict(bindJSON(&Handlers::beginEncrypt), bindBare(&Handlers::endEncrypt)); // .encrypt
manual/cli.rst
@@ -3158,8 +3158,8 @@ Related Options @@ -3158,8 +3158,8 @@ Related Options
3158 3158
3159 Generate a JSON representation of the file. This is described in 3159 Generate a JSON representation of the file. This is described in
3160 depth in the JSON section of the manual. "version" may be a 3160 depth in the JSON section of the manual. "version" may be a
3161 - specific version or "latest". Run qpdf --json-help for a  
3162 - description of the generated JSON object. 3161 + specific version or "latest" (the default). Run qpdf --json-help
  3162 + for a description of the generated JSON object.
3163 3163
3164 Generate a JSON representation of the file. This is described in 3164 Generate a JSON representation of the file. This is described in
3165 depth in :ref:`json`. The version parameter can be used to specify 3165 depth in :ref:`json`. The version parameter can be used to specify
@@ -3258,17 +3258,19 @@ Related Options @@ -3258,17 +3258,19 @@ Related Options
3258 data for the stream stream in object :samp:`{nnn}`. This 3258 data for the stream stream in object :samp:`{nnn}`. This
3259 option only applies when used with :qpdf:ref:`--json-output`. 3259 option only applies when used with :qpdf:ref:`--json-output`.
3260 3260
3261 -.. qpdf:option:: --json-output=version 3261 +.. qpdf:option:: --json-output[=version]
3262 3262
3263 .. help: serialize to JSON 3263 .. help: serialize to JSON
3264 3264
3265 The output file will be qpdf JSON format at the given version. 3265 The output file will be qpdf JSON format at the given version.
3266 - Only version 2 is supported. See also --json-stream-data  
3267 - and --json-stream-prefix  
3268 -  
3269 - The output file will be qpdf JSON format at the given version. Only  
3270 - version 2 is supported. See also :qpdf:ref:`--json-stream-data` and  
3271 - :qpdf:ref:`--json-stream-prefix`. 3266 + "version" may be a specific version or "latest" (the default).
  3267 + Version 1 is not supported. See also --json-stream-data
  3268 + and --json-stream-prefix.
  3269 +
  3270 + The output file will be qpdf JSON format at the given version.
  3271 + ``version`` may be a specific version or ``latest`` (the default).
  3272 + Version 1 is not supported. See also :qpdf:ref:`--json-stream-data`
  3273 + and :qpdf:ref:`--json-stream-prefix`.
3272 3274
3273 .. qpdf:option:: --json-input 3275 .. qpdf:option:: --json-input
3274 3276
qpdf/qtest/qpdf-json.test
@@ -67,15 +67,17 @@ foreach my $i (@goodfiles) @@ -67,15 +67,17 @@ foreach my $i (@goodfiles)
67 if (ref($i) eq 'ARRAY') { 67 if (ref($i) eq 'ARRAY') {
68 ($f, $xargs) = @$i; 68 ($f, $xargs) = @$i;
69 } 69 }
  70 + # explicit "latest" as --json-output version
70 $td->runtest("good: $f -> JSON", 71 $td->runtest("good: $f -> JSON",
71 {$td->COMMAND => "qpdf $xargs --decode-level=none" . 72 {$td->COMMAND => "qpdf $xargs --decode-level=none" .
72 " --json-output=latest $f a.json"}, 73 " --json-output=latest $f a.json"},
73 {$td->STRING => "", $td->EXIT_STATUS => 0}, 74 {$td->STRING => "", $td->EXIT_STATUS => 0},
74 $td->NORMALIZE_NEWLINES); 75 $td->NORMALIZE_NEWLINES);
  76 + # default --json-output version
75 $td->runtest("good: $f JSON -> JSON", 77 $td->runtest("good: $f JSON -> JSON",
76 {$td->COMMAND => 78 {$td->COMMAND =>
77 "qpdf --decode-level=none" . 79 "qpdf --decode-level=none" .
78 - " --json-input --json-output=latest a.json b.json"}, 80 + " --json-input --json-output a.json b.json"},
79 {$td->STRING => "", $td->EXIT_STATUS => 0}, 81 {$td->STRING => "", $td->EXIT_STATUS => 0},
80 $td->NORMALIZE_NEWLINES); 82 $td->NORMALIZE_NEWLINES);
81 $td->runtest("good: $f JSON -> QDF", 83 $td->runtest("good: $f JSON -> QDF",