Skip to content

Commit 2acd977

Browse files
committed
improve layout of command-line tools help page
1 parent 12960b8 commit 2acd977

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

examples/heif_dec.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <cstring>
2929
#include <getopt.h>
30+
#include <filesystem>
3031
#include "libheif/heif_items.h"
3132

3233
#if defined(HAVE_UNISTD_H)
@@ -72,10 +73,18 @@
7273

7374
static void show_help(const char* argv0)
7475
{
75-
std::cerr << " " << argv0 << " libheif version: " << heif_get_version() << "\n"
76-
<< "---------------------------------------\n"
77-
"Usage: " << argv0 << " [options] <input-image> [output-image]\n"
78-
"\n"
76+
std::filesystem::path p(argv0);
77+
std::string filename = p.filename().string();
78+
79+
std::stringstream sstr;
80+
sstr << " " << filename << " libheif version: " << heif_get_version();
81+
82+
std::string title = sstr.str();
83+
84+
std::cerr << title << "\n"
85+
<< std::string(title.length() + 1, '-') << "\n"
86+
<< "Usage: " << filename << " [options] <input-image> [output-image]\n"
87+
<< "\n"
7988
"The program determines the output file format from the output filename suffix.\n"
8089
"These suffixes are recognized: jpg, jpeg, png, tif, tiff, y4m. If no output filename is specified, 'jpg' is used.\n"
8190
"\n"

examples/heif_enc.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,17 @@ static struct option long_options[] = {
159159

160160
void show_help(const char* argv0)
161161
{
162-
std::cerr << " heif-enc libheif version: " << heif_get_version() << "\n"
163-
<< "----------------------------------------\n"
164-
<< "Usage: heif-enc [options] image.jpeg ...\n"
162+
std::filesystem::path p(argv0);
163+
std::string filename = p.filename().string();
164+
165+
std::stringstream sstr;
166+
sstr << " " << filename << " libheif version: " << heif_get_version();
167+
168+
std::string title = sstr.str();
169+
170+
std::cerr << title << "\n"
171+
<< std::string(title.length() + 1, '-') << "\n"
172+
<< "Usage: " << filename << " [options] <input-image> ...\n"
165173
<< "\n"
166174
<< "When specifying multiple source images, they will all be saved into the same HEIF/AVIF file.\n"
167175
<< "\n"

examples/heif_info.cc

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <getopt.h>
4848
#include <assert.h>
4949
#include <stdio.h>
50+
#include <filesystem>
5051
#include "common.h"
5152

5253

@@ -91,17 +92,25 @@ static const char* fourcc_to_string(uint32_t fourcc)
9192

9293
void show_help(const char* argv0)
9394
{
94-
fprintf(stderr, " heif-info libheif version: %s\n", heif_get_version());
95-
fprintf(stderr, "------------------------------------\n");
96-
fprintf(stderr, "usage: heif-info [options] image.heic\n");
97-
fprintf(stderr, "\n");
98-
fprintf(stderr, "options:\n");
99-
//fprintf(stderr," -w, --write-raw ID write raw compressed data of image 'ID'\n");
100-
//fprintf(stderr," -o, --output NAME output file name for image selected by -w\n");
101-
fprintf(stderr, " -d, --dump-boxes show a low-level dump of all MP4 file boxes\n");
102-
fprintf(stderr, " --disable-limits disable all security limits (do not use in production environment)\n");
103-
fprintf(stderr, " -h, --help show help\n");
104-
fprintf(stderr, " -v, --version show version\n");
95+
std::filesystem::path p(argv0);
96+
std::string filename = p.filename().string();
97+
98+
std::stringstream sstr;
99+
sstr << " " << filename << " libheif version: " << heif_get_version();
100+
101+
std::string title = sstr.str();
102+
103+
std::cerr << title << "\n"
104+
<< std::string(title.length() + 1, '-') << "\n"
105+
<< "Usage: " << filename << " [options] <HEIF-image>\n"
106+
<< "\n"
107+
"options:\n"
108+
//fprintf(stderr," -w, --write-raw ID write raw compressed data of image 'ID'\n");
109+
//fprintf(stderr," -o, --output NAME output file name for image selected by -w\n");
110+
" -d, --dump-boxes show a low-level dump of all MP4 file boxes\n"
111+
" --disable-limits disable all security limits (do not use in production environment)\n"
112+
" -h, --help show help\n"
113+
" -v, --version show version\n";
105114
}
106115

107116

0 commit comments

Comments
 (0)