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.
This commit is contained in:
m-holger 2022-02-07 13:07:09 +00:00 committed by Jay Berkenbilt
parent 4fd619818c
commit 3e98fe46a2
11 changed files with 34 additions and 35 deletions

View File

@ -22,13 +22,13 @@ void usage()
std::cerr << "Usage: " << whoami << " [options] file.pdf [password]"
<< std::endl
<< "Options:" << std::endl
<< " -numbers give bookmarks outline-style numbers"
<< " --numbers give bookmarks outline-style numbers"
<< std::endl
<< " -lines draw lines to show bookmark hierarchy"
<< " --lines draw lines to show bookmark hierarchy"
<< std::endl
<< " -show-open indicate whether a bookmark is initially open"
<< " --show-open indicate whether a bookmark is initially open"
<< std::endl
<< " -show-targets show target if possible"
<< " --show-targets show target if possible"
<< std::endl;
exit(2);
}
@ -177,19 +177,19 @@ int main(int argc, char* argv[])
{
if (argv[arg][0] == '-')
{
if (strcmp(argv[arg], "-numbers") == 0)
if (strcmp(argv[arg], "--numbers") == 0)
{
style = st_numbers;
}
else if (strcmp(argv[arg], "-lines") == 0)
else if (strcmp(argv[arg], "--lines") == 0)
{
style = st_lines;
}
else if (strcmp(argv[arg], "-show-open") == 0)
else if (strcmp(argv[arg], "--show-open") == 0)
{
show_open = true;
}
else if (strcmp(argv[arg], "-show-targets") == 0)
else if (strcmp(argv[arg], "--show-targets") == 0)
{
show_targets = true;
}

View File

@ -461,7 +461,7 @@ static void usage()
{
std::cerr
<< "\n"
<< "Usage: " << whoami << " [ --decode-specialized ] infile outfile\n"
<< "Usage: " << whoami << " [--decode-specialized] infile outfile\n"
<< std::endl;
exit(2);
}

View File

@ -17,7 +17,7 @@ void usage()
{
std::cerr
<< "Usage: " << whoami
<< " -in in_file [-out out_file] [-key key [-val val]?]+\n"
<< " --in in_file [--out out_file] [--key key [--val val]?]+\n"
<< "Modifies/Adds/Removes PDF /Info entries in the in_file\n"
<< "and stores the result in out_file\n"
<< "Special mode: " << whoami << " --dump file\n"
@ -86,11 +86,10 @@ int main(int argc, char* argv[])
std::cout << whoami << " version " << version << std::endl;
exit(0);
}
if ((argc == 4) && (! strcmp(argv[1], "--dump")) &&
(strcmp(argv[2], "-in") == 0) )
if ((argc == 3) && (! strcmp(argv[1], "--dump")))
{
QTC::TC("examples", "pdf-mod-info --dump");
pdfDumpInfoDict(argv[3]);
pdfDumpInfoDict(argv[2]);
exit(0);
}
@ -100,11 +99,11 @@ int main(int argc, char* argv[])
for (int i = 1; i < argc; ++i)
{
if ((! strcmp(argv[i], "-in")) && (++i < argc))
if ((! strcmp(argv[i], "--in")) && (++i < argc))
{
fl_in = argv[i];
}
else if ((! strcmp(argv[i], "-out")) && (++i < argc))
else if ((! strcmp(argv[i], "--out")) && (++i < argc))
{
fl_out = argv[i];
}
@ -112,7 +111,7 @@ int main(int argc, char* argv[])
{
static_id = true; // this should be used in test suites only
}
else if ((! strcmp(argv[i], "-key")) && (++i < argc))
else if ((! strcmp(argv[i], "--key")) && (++i < argc))
{
QTC::TC("examples", "pdf-mod-info -key");
cur_key = argv[i];
@ -122,7 +121,7 @@ int main(int argc, char* argv[])
}
Keys[cur_key] = "";
}
else if ((! strcmp(argv[i], "-val")) && (++i < argc))
else if ((! strcmp(argv[i], "--val")) && (++i < argc))
{
if (cur_key.empty())
{

View File

@ -9,9 +9,9 @@ require TestDriver;
my $td = new TestDriver('pdf-bookmarks');
foreach my $show ("", " -show-open")
foreach my $show ("", " --show-open")
{
foreach my $style ("", " -lines", " -numbers")
foreach my $style ("", " --lines", " --numbers")
{
my $xshow = $show ? $show : "x";
my $xstyle = $style ? $style : "x";
@ -37,7 +37,7 @@ $td->runtest("bad",
$td->NORMALIZE_NEWLINES);
$td->runtest("encrypted, targets",
{$td->COMMAND => "pdf-bookmarks -show-targets 4.pdf user"},
{$td->COMMAND => "pdf-bookmarks --show-targets 4.pdf user"},
{$td->FILE => "encrypted.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);

View File

@ -16,64 +16,64 @@ my $qpdf = $ENV{'QPDF_BIN'} or die;
cleanup();
$td->runtest("usage #1",
{$td->COMMAND => "$prg -in target.pdf"},
{$td->COMMAND => "$prg --in target.pdf"},
{$td->FILE => "usage.out",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("usage #2",
{$td->COMMAND => "$prg -key abc -val def"},
{$td->COMMAND => "$prg --key abc --val def"},
{$td->FILE => "usage.out",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("usage #3",
{$td->COMMAND => "$prg -key abc -val def abc"},
{$td->COMMAND => "$prg --key abc --val def abc"},
{$td->FILE => "usage.out",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("usage #4",
{$td->COMMAND => "$prg -in source1.pdf -key date -val 01/01/01 -val 12/12/12"},
{$td->COMMAND => "$prg --in source1.pdf --key date --val 01/01/01 --val 12/12/12"},
{$td->FILE => "usage.out",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("dump #1",
{$td->COMMAND => "$prg --dump -in files/source1.pdf"},
{$td->COMMAND => "$prg --dump files/source1.pdf"},
{$td->FILE => "dump.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("dump #2",
{$td->COMMAND => "$prg --dump -in files/no-info.pdf"},
{$td->COMMAND => "$prg --dump files/no-info.pdf"},
{$td->STRING => "",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("dump #3",
{$td->COMMAND => "$prg --dump -in files/empty-info.pdf"},
{$td->COMMAND => "$prg --dump files/empty-info.pdf"},
{$td->STRING => "",
$td->EXIT_STATUS => 0});
run_and_cmp("modify Subject",
"$prg -in files/source1.pdf -out out.pdf -key Subject " .
"-val \"Export Business\"",
"$prg --in files/source1.pdf --out out.pdf --key Subject " .
"--val \"Export Business\"",
"", "out.pdf", "files/1.qdf");
run_and_cmp("add Subject, remove Producer, modify CreationDate",
"$prg -in files/source2.pdf -out out.pdf -key Subject " .
"-val \"Tammlin\" -key Producer -key CreationDate -val 12/12",
"$prg --in files/source2.pdf --out out.pdf --key Subject " .
"--val \"Tammlin\" --key Producer --key CreationDate --val 12/12",
"", "out.pdf", "files/2.qdf");
run_and_cmp("add Subject (empty-info file)",
"$prg -in files/empty-info.pdf -out out.pdf -key Subject " .
"-val Tammlin",
"$prg --in files/empty-info.pdf --out out.pdf --key Subject " .
"--val Tammlin",
"", "out.pdf", "files/3.qdf");
copy("files/no-info.pdf", "no-info.pdf") or die "can't copy no-info: $!";
run_and_cmp("in-place Producer added (no-info file)",
"$prg -in no-info.pdf -key Producer -val \"Obivan Kinobi\"",
"$prg --in no-info.pdf --key Producer --val \"Obivan Kinobi\"",
"", "no-info.pdf", "files/4.qdf");
cleanup();

View File

@ -1,4 +1,4 @@
Usage: pdf-mod-info -in in_file [-out out_file] [-key key [-val val]?]+
Usage: pdf-mod-info --in in_file [--out out_file] [--key key [--val val]?]+
Modifies/Adds/Removes PDF /Info entries in the in_file
and stores the result in out_file
Special mode: pdf-mod-info --dump file