Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use help2man to generate a man page #40

Merged
merged 4 commits into from Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions CMakeLists.txt
@@ -1,5 +1,6 @@
cmake_minimum_required (VERSION 2.8.5)
project (microdnf C)
set (PROJECT_VERSION 3.0.1)

list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

Expand All @@ -25,6 +26,25 @@ set (PKG_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/dnf)
add_definitions (-DPACKAGE_LIBDIR="${PKG_LIBDIR}")
add_definitions (-DPACKAGE_DATADIR="${PKG_DATADIR}")

find_file (HELP2MAN_EXECUTABLE help2man)
if (NOT HELP2MAN_EXECUTABLE)
message (FATAL_ERROR "unable to find help2man")
endif ()

set (MANPAGE ${CMAKE_CURRENT_BINARY_DIR}/microdnf.8)
add_custom_command (
DEPENDS microdnf
OUTPUT ${MANPAGE}
COMMAND ${HELP2MAN_EXECUTABLE} $<TARGET_FILE:microdnf>
--version-string=${PROJECT_VERSION}
--no-info
--section=8
--name="Micro DNF"
--output=${MANPAGE}
)
add_custom_target (manpage ALL DEPENDS ${MANPAGE})
install (FILES ${MANPAGE} DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man8)

include_directories (${GLIB_INCLUDE_DIRS})
include_directories (${GOBJECT_INCLUDE_DIRS})
include_directories (${PEAS_INCLUDE_DIRS})
Expand Down
11 changes: 9 additions & 2 deletions dnf/dnf-main.c
Expand Up @@ -210,7 +210,11 @@ main (int argc,
if (!peas_engine_load_plugin (engine, info))
continue;
if (peas_engine_provides_extension (engine, info, DNF_TYPE_COMMAND))
g_string_append_printf (cmd_summary, "\n %s - %s", peas_plugin_info_get_name (info), peas_plugin_info_get_description (info));
/*
* At least 2 spaces between the command and its description are needed
* so that help2man formats it correctly.
*/
g_string_append_printf (cmd_summary, "\n %-16s %s", peas_plugin_info_get_name (info), peas_plugin_info_get_description (info));
}
g_option_context_set_summary (opt_ctx, cmd_summary->str);
g_string_free (cmd_summary, TRUE);
Expand Down Expand Up @@ -274,7 +278,10 @@ main (int argc,

if (cmd_name == NULL && show_help)
{
g_set_prgname (argv[0]);
const char *prg_name = strrchr(argv[0], '/') + 1;
prg_name = prg_name ? prg_name : argv[0];

g_set_prgname (prg_name);
g_autofree gchar *help = g_option_context_get_help (opt_ctx, TRUE, NULL);
g_print ("%s", help);
goto out;
Expand Down
2 changes: 1 addition & 1 deletion dnf/meson.build
Expand Up @@ -40,7 +40,7 @@ microdnf_srcs = [
'plugins/clean/dnf-command-clean.c',
]

executable(
microdnf = executable(
'microdnf',
sources : microdnf_srcs,
dependencies : [
Expand Down
21 changes: 20 additions & 1 deletion meson.build
@@ -1,5 +1,5 @@
project('microdnf', 'c',
version : '1',
version : '3.0.1',
license : 'GPL-3.0+',
default_options : [
'b_asneeded=True',
Expand Down Expand Up @@ -44,3 +44,22 @@ add_project_arguments(
)

subdir('dnf')

help2man = find_program('help2man', required: true)
if help2man.found()
help2man_opts = [
'--version-string=' + meson.project_version(),
'--no-info',
'--section=8',
'--name=Micro DNF',
]

custom_target('microdnf.8',
output: 'microdnf.8',
command: [
help2man, help2man_opts, '--output=@OUTPUT@', microdnf
],
install: true,
install_dir: get_option('mandir') + '/man8',
)
endif