Commit 80acfc3826704064db8cc2f6af0c338b3aa557e7

Authored by Jay Berkenbilt
1 parent 69820847

Fix --json-help to take a version parameter

include/qpdf/QPDFJob.hh
... ... @@ -46,6 +46,8 @@ class QPDFLogger;
46 46 class QPDFJob
47 47 {
48 48 public:
  49 + static int constexpr LATEST_JOB_JSON = 1;
  50 +
49 51 // Exit codes -- returned by getExitCode() after calling run()
50 52 static int constexpr EXIT_ERROR = qpdf_exit_error;
51 53 static int constexpr EXIT_WARNING = qpdf_exit_warning;
... ... @@ -426,14 +428,23 @@ class QPDFJob
426 428 doIfVerbose(std::function<void(Pipeline&, std::string const& prefix)> fn);
427 429  
428 430 // Provide a string that is the help information ("schema" for the
429   - // qpdf-specific JSON object) for version 1 of the JSON output.
  431 + // qpdf-specific JSON object) for the specified version of JSON
  432 + // output.
  433 + QPDF_DLL
  434 + static std::string json_out_schema(int version);
  435 +
  436 + QPDF_DLL
  437 + [[deprecated("use json_out_schema(version)")]] static std::string
  438 + json_out_schema_v1();
  439 +
  440 + // Provide a string that is the help information for specified
  441 + // version of JSON format for QPDFJob.
430 442 QPDF_DLL
431   - static std::string json_out_schema_v1();
  443 + static std::string job_json_schema(int version);
432 444  
433   - // Provide a string that is the help information for the version 1
434   - // of JSON format for QPDFJob.
435 445 QPDF_DLL
436   - static std::string job_json_schema_v1();
  446 + [[deprecated("use job_json_schema(version)")]] static std::string
  447 + job_json_schema_v1();
437 448  
438 449 private:
439 450 struct RotationSpec
... ...
job.sums
... ... @@ -6,10 +6,10 @@ include/qpdf/auto_job_c_enc.hh 28446f3c32153a52afa239ea40503e6cc8ac2c026813526a3
6 6 include/qpdf/auto_job_c_main.hh cdba1ae6ea5525a585d10a3dd95b7996d62b17de4211fe658b78d9d463b0f313
7 7 include/qpdf/auto_job_c_pages.hh b3cc0f21029f6d89efa043dcdbfa183cb59325b6506001c18911614fe8e568ec
8 8 include/qpdf/auto_job_c_uo.hh ae21b69a1efa9333050f4833d465f6daff87e5b38e5106e49bbef5d4132e4ed1
9   -job.yml ad7c086267fe6f309bf0838840f22cbd95326259cad148b4d5e6699b49f5f379
10   -libqpdf/qpdf/auto_job_decl.hh 74df4d7fdbdf51ecd0d58ce1e9844bb5525b9adac5a45f7c9a787ecdda2868df
  9 +job.yml f9564f18b08a45d17328af43652645771d3498471820c858b8c9013a193e1412
  10 +libqpdf/qpdf/auto_job_decl.hh 7844eba58edffb9494b19e8eca6fd59a24d6e152ca606c3b07da569f753df2da
11 11 libqpdf/qpdf/auto_job_help.hh db2e4350c700e064b204e3e20d4fee4eddfe312b28092afcf608b4b6863d30e5
12   -libqpdf/qpdf/auto_job_init.hh 3c3576b6d1d79fda64ae53f08fd9fd2b42c86f3c1d52dd4db0d7f2d4d64b9b4a
  12 +libqpdf/qpdf/auto_job_init.hh fd1635a5ad6ba16b7ae008467145560a59a5ecfd10d29c5ef7cd0d8347747cd2
13 13 libqpdf/qpdf/auto_job_json_decl.hh 06caa46eaf71db8a50c046f91866baa8087745a9474319fb7c86d92634cc8297
14 14 libqpdf/qpdf/auto_job_json_init.hh 59545578a2e47c660ff98516ed53f06638be75eb4658e2a09d32cc08e0cb7268
15 15 libqpdf/qpdf/auto_job_schema.hh 9d543cd4a43eafffc2c4b8a6fee29e399c271c52cb6f7d417ae5497b3c1127dc
... ...
... ... @@ -75,9 +75,10 @@ options:
75 75 bare:
76 76 - version
77 77 - copyright
78   - - json-help
79 78 - show-crypto
80 79 - job-json-help
  80 + optional_choices:
  81 + json-help: json_version
81 82 - table: main
82 83 config: c_main
83 84 manual:
... ...
libqpdf/QPDFJob.cc
... ... @@ -487,6 +487,15 @@ QPDFJob::config()
487 487 std::string
488 488 QPDFJob::job_json_schema_v1()
489 489 {
  490 + return job_json_schema(1);
  491 +}
  492 +
  493 +std::string
  494 +QPDFJob::job_json_schema(int version)
  495 +{
  496 + if (version != LATEST_JOB_JSON) {
  497 + throw std::runtime_error("job_json_schema: version must be 1");
  498 + }
490 499 return JOB_SCHEMA_DATA;
491 500 }
492 501  
... ... @@ -1753,6 +1762,12 @@ QPDFJob::json_schema(int json_version, std::set&lt;std::string&gt;* keys)
1753 1762 }
1754 1763  
1755 1764 std::string
  1765 +QPDFJob::json_out_schema(int version)
  1766 +{
  1767 + return json_schema(version).unparse();
  1768 +}
  1769 +
  1770 +std::string
1756 1771 QPDFJob::json_out_schema_v1()
1757 1772 {
1758 1773 return json_schema(1).unparse();
... ...
libqpdf/QPDFJob_argv.cc
... ... @@ -143,10 +143,17 @@ ArgParser::argCopyright()
143 143 }
144 144  
145 145 void
146   -ArgParser::argJsonHelp()
  146 +ArgParser::argJsonHelp(std::string const& parameter)
147 147 {
  148 + int version = JSON::LATEST;
  149 + if (!(parameter.empty() || (parameter == "latest"))) {
  150 + version = QUtil::string_to_int(parameter.c_str());
  151 + }
  152 + if ((version < 1) || (version > JSON::LATEST)) {
  153 + usage(std::string("unsupported json version ") + parameter);
  154 + }
148 155 *QPDFLogger::defaultLogger()->getInfo()
149   - << QPDFJob::json_out_schema_v1() << "\n";
  156 + << QPDFJob::json_out_schema(version) << "\n";
150 157 }
151 158  
152 159 void
... ... @@ -396,7 +403,7 @@ void
396 403 ArgParser::argJobJsonHelp()
397 404 {
398 405 *QPDFLogger::defaultLogger()->getInfo()
399   - << QPDFJob::job_json_schema_v1() << "\n";
  406 + << QPDFJob::job_json_schema(QPDFJob::LATEST_JOB_JSON) << "\n";
400 407 }
401 408  
402 409 void
... ...
libqpdf/QPDFJob_json.cc
... ... @@ -10,7 +10,7 @@
10 10 #include <sstream>
11 11 #include <stdexcept>
12 12  
13   -static JSON JOB_SCHEMA = JSON::parse(QPDFJob::job_json_schema_v1().c_str());
  13 +static JSON JOB_SCHEMA = JSON::parse(QPDFJob::job_json_schema(1).c_str());
14 14  
15 15 namespace
16 16 {
... ...
libqpdf/qpdf/auto_job_decl.hh
... ... @@ -16,9 +16,9 @@ static constexpr char const* O_COPY_ATTACHMENT = &quot;copy attachment&quot;;
16 16  
17 17 void argVersion();
18 18 void argCopyright();
19   -void argJsonHelp();
20 19 void argShowCrypto();
21 20 void argJobJsonHelp();
  21 +void argJsonHelp(std::string const&);
22 22 void argPositional(std::string const&);
23 23 void argAddAttachment();
24 24 void argCopyAttachmentsFrom();
... ...
libqpdf/qpdf/auto_job_init.hh
... ... @@ -29,9 +29,9 @@ static char const* modify128_choices[] = {&quot;all&quot;, &quot;annotate&quot;, &quot;form&quot;, &quot;assembly&quot;,
29 29 this->ap.selectHelpOptionTable();
30 30 this->ap.addBare("version", b(&ArgParser::argVersion));
31 31 this->ap.addBare("copyright", b(&ArgParser::argCopyright));
32   -this->ap.addBare("json-help", b(&ArgParser::argJsonHelp));
33 32 this->ap.addBare("show-crypto", b(&ArgParser::argShowCrypto));
34 33 this->ap.addBare("job-json-help", b(&ArgParser::argJobJsonHelp));
  34 +this->ap.addChoices("json-help", p(&ArgParser::argJsonHelp), false, json_version_choices);
35 35 this->ap.selectMainOptionTable();
36 36 this->ap.addPositional(p(&ArgParser::argPositional));
37 37 this->ap.addBare("add-attachment", b(&ArgParser::argAddAttachment));
... ...