Commit 3e98fe46a24d8231ed5f962f5b874032e4994f08

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 4fd61981

Tidy example CLI usage

Change "-" to "--" for named parameters.
Remove spaces inside "[ option ]" for optional parameters.
Fix "pdf-mod-info --dump file" to match usage message.
examples/pdf-bookmarks.cc
@@ -22,13 +22,13 @@ void usage() @@ -22,13 +22,13 @@ void usage()
22 std::cerr << "Usage: " << whoami << " [options] file.pdf [password]" 22 std::cerr << "Usage: " << whoami << " [options] file.pdf [password]"
23 << std::endl 23 << std::endl
24 << "Options:" << std::endl 24 << "Options:" << std::endl
25 - << " -numbers give bookmarks outline-style numbers" 25 + << " --numbers give bookmarks outline-style numbers"
26 << std::endl 26 << std::endl
27 - << " -lines draw lines to show bookmark hierarchy" 27 + << " --lines draw lines to show bookmark hierarchy"
28 << std::endl 28 << std::endl
29 - << " -show-open indicate whether a bookmark is initially open" 29 + << " --show-open indicate whether a bookmark is initially open"
30 << std::endl 30 << std::endl
31 - << " -show-targets show target if possible" 31 + << " --show-targets show target if possible"
32 << std::endl; 32 << std::endl;
33 exit(2); 33 exit(2);
34 } 34 }
@@ -177,19 +177,19 @@ int main(int argc, char* argv[]) @@ -177,19 +177,19 @@ int main(int argc, char* argv[])
177 { 177 {
178 if (argv[arg][0] == '-') 178 if (argv[arg][0] == '-')
179 { 179 {
180 - if (strcmp(argv[arg], "-numbers") == 0) 180 + if (strcmp(argv[arg], "--numbers") == 0)
181 { 181 {
182 style = st_numbers; 182 style = st_numbers;
183 } 183 }
184 - else if (strcmp(argv[arg], "-lines") == 0) 184 + else if (strcmp(argv[arg], "--lines") == 0)
185 { 185 {
186 style = st_lines; 186 style = st_lines;
187 } 187 }
188 - else if (strcmp(argv[arg], "-show-open") == 0) 188 + else if (strcmp(argv[arg], "--show-open") == 0)
189 { 189 {
190 show_open = true; 190 show_open = true;
191 } 191 }
192 - else if (strcmp(argv[arg], "-show-targets") == 0) 192 + else if (strcmp(argv[arg], "--show-targets") == 0)
193 { 193 {
194 show_targets = true; 194 show_targets = true;
195 } 195 }
examples/pdf-custom-filter.cc
@@ -461,7 +461,7 @@ static void usage() @@ -461,7 +461,7 @@ static void usage()
461 { 461 {
462 std::cerr 462 std::cerr
463 << "\n" 463 << "\n"
464 - << "Usage: " << whoami << " [ --decode-specialized ] infile outfile\n" 464 + << "Usage: " << whoami << " [--decode-specialized] infile outfile\n"
465 << std::endl; 465 << std::endl;
466 exit(2); 466 exit(2);
467 } 467 }
examples/pdf-mod-info.cc
@@ -17,7 +17,7 @@ void usage() @@ -17,7 +17,7 @@ void usage()
17 { 17 {
18 std::cerr 18 std::cerr
19 << "Usage: " << whoami 19 << "Usage: " << whoami
20 - << " -in in_file [-out out_file] [-key key [-val val]?]+\n" 20 + << " --in in_file [--out out_file] [--key key [--val val]?]+\n"
21 << "Modifies/Adds/Removes PDF /Info entries in the in_file\n" 21 << "Modifies/Adds/Removes PDF /Info entries in the in_file\n"
22 << "and stores the result in out_file\n" 22 << "and stores the result in out_file\n"
23 << "Special mode: " << whoami << " --dump file\n" 23 << "Special mode: " << whoami << " --dump file\n"
@@ -86,11 +86,10 @@ int main(int argc, char* argv[]) @@ -86,11 +86,10 @@ int main(int argc, char* argv[])
86 std::cout << whoami << " version " << version << std::endl; 86 std::cout << whoami << " version " << version << std::endl;
87 exit(0); 87 exit(0);
88 } 88 }
89 - if ((argc == 4) && (! strcmp(argv[1], "--dump")) &&  
90 - (strcmp(argv[2], "-in") == 0) ) 89 + if ((argc == 3) && (! strcmp(argv[1], "--dump")))
91 { 90 {
92 QTC::TC("examples", "pdf-mod-info --dump"); 91 QTC::TC("examples", "pdf-mod-info --dump");
93 - pdfDumpInfoDict(argv[3]); 92 + pdfDumpInfoDict(argv[2]);
94 exit(0); 93 exit(0);
95 } 94 }
96 95
@@ -100,11 +99,11 @@ int main(int argc, char* argv[]) @@ -100,11 +99,11 @@ int main(int argc, char* argv[])
100 99
101 for (int i = 1; i < argc; ++i) 100 for (int i = 1; i < argc; ++i)
102 { 101 {
103 - if ((! strcmp(argv[i], "-in")) && (++i < argc)) 102 + if ((! strcmp(argv[i], "--in")) && (++i < argc))
104 { 103 {
105 fl_in = argv[i]; 104 fl_in = argv[i];
106 } 105 }
107 - else if ((! strcmp(argv[i], "-out")) && (++i < argc)) 106 + else if ((! strcmp(argv[i], "--out")) && (++i < argc))
108 { 107 {
109 fl_out = argv[i]; 108 fl_out = argv[i];
110 } 109 }
@@ -112,7 +111,7 @@ int main(int argc, char* argv[]) @@ -112,7 +111,7 @@ int main(int argc, char* argv[])
112 { 111 {
113 static_id = true; // this should be used in test suites only 112 static_id = true; // this should be used in test suites only
114 } 113 }
115 - else if ((! strcmp(argv[i], "-key")) && (++i < argc)) 114 + else if ((! strcmp(argv[i], "--key")) && (++i < argc))
116 { 115 {
117 QTC::TC("examples", "pdf-mod-info -key"); 116 QTC::TC("examples", "pdf-mod-info -key");
118 cur_key = argv[i]; 117 cur_key = argv[i];
@@ -122,7 +121,7 @@ int main(int argc, char* argv[]) @@ -122,7 +121,7 @@ int main(int argc, char* argv[])
122 } 121 }
123 Keys[cur_key] = ""; 122 Keys[cur_key] = "";
124 } 123 }
125 - else if ((! strcmp(argv[i], "-val")) && (++i < argc)) 124 + else if ((! strcmp(argv[i], "--val")) && (++i < argc))
126 { 125 {
127 if (cur_key.empty()) 126 if (cur_key.empty())
128 { 127 {
examples/qtest/bookmarks.test
@@ -9,9 +9,9 @@ require TestDriver; @@ -9,9 +9,9 @@ require TestDriver;
9 9
10 my $td = new TestDriver('pdf-bookmarks'); 10 my $td = new TestDriver('pdf-bookmarks');
11 11
12 -foreach my $show ("", " -show-open") 12 +foreach my $show ("", " --show-open")
13 { 13 {
14 - foreach my $style ("", " -lines", " -numbers") 14 + foreach my $style ("", " --lines", " --numbers")
15 { 15 {
16 my $xshow = $show ? $show : "x"; 16 my $xshow = $show ? $show : "x";
17 my $xstyle = $style ? $style : "x"; 17 my $xstyle = $style ? $style : "x";
@@ -37,7 +37,7 @@ $td-&gt;runtest(&quot;bad&quot;, @@ -37,7 +37,7 @@ $td-&gt;runtest(&quot;bad&quot;,
37 $td->NORMALIZE_NEWLINES); 37 $td->NORMALIZE_NEWLINES);
38 38
39 $td->runtest("encrypted, targets", 39 $td->runtest("encrypted, targets",
40 - {$td->COMMAND => "pdf-bookmarks -show-targets 4.pdf user"}, 40 + {$td->COMMAND => "pdf-bookmarks --show-targets 4.pdf user"},
41 {$td->FILE => "encrypted.out", 41 {$td->FILE => "encrypted.out",
42 $td->EXIT_STATUS => 0}, 42 $td->EXIT_STATUS => 0},
43 $td->NORMALIZE_NEWLINES); 43 $td->NORMALIZE_NEWLINES);
examples/qtest/bookmarks/test.-show-open.-lines.out renamed to examples/qtest/bookmarks/test.--show-open.--lines.out
examples/qtest/bookmarks/test.-show-open.-numbers.out renamed to examples/qtest/bookmarks/test.--show-open.--numbers.out
examples/qtest/bookmarks/test.-show-open.x.out renamed to examples/qtest/bookmarks/test.--show-open.x.out
examples/qtest/bookmarks/test.x.-lines.out renamed to examples/qtest/bookmarks/test.x.--lines.out
examples/qtest/bookmarks/test.x.-numbers.out renamed to examples/qtest/bookmarks/test.x.--numbers.out
examples/qtest/mod-info.test
@@ -16,64 +16,64 @@ my $qpdf = $ENV{&#39;QPDF_BIN&#39;} or die; @@ -16,64 +16,64 @@ my $qpdf = $ENV{&#39;QPDF_BIN&#39;} or die;
16 cleanup(); 16 cleanup();
17 17
18 $td->runtest("usage #1", 18 $td->runtest("usage #1",
19 - {$td->COMMAND => "$prg -in target.pdf"}, 19 + {$td->COMMAND => "$prg --in target.pdf"},
20 {$td->FILE => "usage.out", 20 {$td->FILE => "usage.out",
21 $td->EXIT_STATUS => 2}, 21 $td->EXIT_STATUS => 2},
22 $td->NORMALIZE_NEWLINES); 22 $td->NORMALIZE_NEWLINES);
23 23
24 $td->runtest("usage #2", 24 $td->runtest("usage #2",
25 - {$td->COMMAND => "$prg -key abc -val def"}, 25 + {$td->COMMAND => "$prg --key abc --val def"},
26 {$td->FILE => "usage.out", 26 {$td->FILE => "usage.out",
27 $td->EXIT_STATUS => 2}, 27 $td->EXIT_STATUS => 2},
28 $td->NORMALIZE_NEWLINES); 28 $td->NORMALIZE_NEWLINES);
29 29
30 $td->runtest("usage #3", 30 $td->runtest("usage #3",
31 - {$td->COMMAND => "$prg -key abc -val def abc"}, 31 + {$td->COMMAND => "$prg --key abc --val def abc"},
32 {$td->FILE => "usage.out", 32 {$td->FILE => "usage.out",
33 $td->EXIT_STATUS => 2}, 33 $td->EXIT_STATUS => 2},
34 $td->NORMALIZE_NEWLINES); 34 $td->NORMALIZE_NEWLINES);
35 35
36 $td->runtest("usage #4", 36 $td->runtest("usage #4",
37 - {$td->COMMAND => "$prg -in source1.pdf -key date -val 01/01/01 -val 12/12/12"}, 37 + {$td->COMMAND => "$prg --in source1.pdf --key date --val 01/01/01 --val 12/12/12"},
38 {$td->FILE => "usage.out", 38 {$td->FILE => "usage.out",
39 $td->EXIT_STATUS => 2}, 39 $td->EXIT_STATUS => 2},
40 $td->NORMALIZE_NEWLINES); 40 $td->NORMALIZE_NEWLINES);
41 41
42 $td->runtest("dump #1", 42 $td->runtest("dump #1",
43 - {$td->COMMAND => "$prg --dump -in files/source1.pdf"}, 43 + {$td->COMMAND => "$prg --dump files/source1.pdf"},
44 {$td->FILE => "dump.out", 44 {$td->FILE => "dump.out",
45 $td->EXIT_STATUS => 0}, 45 $td->EXIT_STATUS => 0},
46 $td->NORMALIZE_NEWLINES); 46 $td->NORMALIZE_NEWLINES);
47 47
48 $td->runtest("dump #2", 48 $td->runtest("dump #2",
49 - {$td->COMMAND => "$prg --dump -in files/no-info.pdf"}, 49 + {$td->COMMAND => "$prg --dump files/no-info.pdf"},
50 {$td->STRING => "", 50 {$td->STRING => "",
51 $td->EXIT_STATUS => 0}, 51 $td->EXIT_STATUS => 0},
52 $td->NORMALIZE_NEWLINES); 52 $td->NORMALIZE_NEWLINES);
53 53
54 $td->runtest("dump #3", 54 $td->runtest("dump #3",
55 - {$td->COMMAND => "$prg --dump -in files/empty-info.pdf"}, 55 + {$td->COMMAND => "$prg --dump files/empty-info.pdf"},
56 {$td->STRING => "", 56 {$td->STRING => "",
57 $td->EXIT_STATUS => 0}); 57 $td->EXIT_STATUS => 0});
58 58
59 run_and_cmp("modify Subject", 59 run_and_cmp("modify Subject",
60 - "$prg -in files/source1.pdf -out out.pdf -key Subject " .  
61 - "-val \"Export Business\"", 60 + "$prg --in files/source1.pdf --out out.pdf --key Subject " .
  61 + "--val \"Export Business\"",
62 "", "out.pdf", "files/1.qdf"); 62 "", "out.pdf", "files/1.qdf");
63 63
64 run_and_cmp("add Subject, remove Producer, modify CreationDate", 64 run_and_cmp("add Subject, remove Producer, modify CreationDate",
65 - "$prg -in files/source2.pdf -out out.pdf -key Subject " .  
66 - "-val \"Tammlin\" -key Producer -key CreationDate -val 12/12", 65 + "$prg --in files/source2.pdf --out out.pdf --key Subject " .
  66 + "--val \"Tammlin\" --key Producer --key CreationDate --val 12/12",
67 "", "out.pdf", "files/2.qdf"); 67 "", "out.pdf", "files/2.qdf");
68 68
69 run_and_cmp("add Subject (empty-info file)", 69 run_and_cmp("add Subject (empty-info file)",
70 - "$prg -in files/empty-info.pdf -out out.pdf -key Subject " .  
71 - "-val Tammlin", 70 + "$prg --in files/empty-info.pdf --out out.pdf --key Subject " .
  71 + "--val Tammlin",
72 "", "out.pdf", "files/3.qdf"); 72 "", "out.pdf", "files/3.qdf");
73 73
74 copy("files/no-info.pdf", "no-info.pdf") or die "can't copy no-info: $!"; 74 copy("files/no-info.pdf", "no-info.pdf") or die "can't copy no-info: $!";
75 run_and_cmp("in-place Producer added (no-info file)", 75 run_and_cmp("in-place Producer added (no-info file)",
76 - "$prg -in no-info.pdf -key Producer -val \"Obivan Kinobi\"", 76 + "$prg --in no-info.pdf --key Producer --val \"Obivan Kinobi\"",
77 "", "no-info.pdf", "files/4.qdf"); 77 "", "no-info.pdf", "files/4.qdf");
78 78
79 cleanup(); 79 cleanup();
examples/qtest/mod-info/usage.out
1 -Usage: pdf-mod-info -in in_file [-out out_file] [-key key [-val val]?]+ 1 +Usage: pdf-mod-info --in in_file [--out out_file] [--key key [--val val]?]+
2 Modifies/Adds/Removes PDF /Info entries in the in_file 2 Modifies/Adds/Removes PDF /Info entries in the in_file
3 and stores the result in out_file 3 and stores the result in out_file
4 Special mode: pdf-mod-info --dump file 4 Special mode: pdf-mod-info --dump file