From dfd1636f18bf7c893a66fc102deda319feb1f6b5 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Mon, 11 Mar 2024 14:16:05 +0200 Subject: [PATCH 1/3] scripts: add `gen_man_pages.sh` script --- scripts/gen_man_pages.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 scripts/gen_man_pages.sh diff --git a/scripts/gen_man_pages.sh b/scripts/gen_man_pages.sh new file mode 100755 index 000000000..f70708e07 --- /dev/null +++ b/scripts/gen_man_pages.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Usage: ./gen_man_pages.sh DESTDIR PREFIX + +DESTDIR="$1" +PREFIX="$2" + +# Check if lncli is installed. +if ! command -v lncli &> /dev/null +then + echo "lncli could not be found. Please install lncli before running this script." + exit 1 +fi + +# Ignore warnings regarding HTMLBlock detection in go-md2man package +# since using "<...>" is part of our docs. +lncli generatemanpage 2>&1 | grep -v "go-md2man does not handle node type HTMLSpan" || true + +echo "Installing man pages to $DESTDIR$PREFIX/share/man/man1." +install -m 644 lnd.1 "$DESTDIR$PREFIX/share/man/man1/lnd.1" +install -m 644 lncli.1 "$DESTDIR$PREFIX/share/man/man1/lncli.1" + +# Remove lncli.1 and lnd.1 artifacts from the current working directory. +rm -f lncli.1 lnd.1 From 158b802f496f6879238d0060f63bd13ffe90073c Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Wed, 6 Mar 2024 17:25:58 +0200 Subject: [PATCH 2/3] lncli+makefile: generate man pages automatically for lncli and lnd --- Makefile | 14 ++++++++++++-- cmd/lncli/commands.go | 37 +++++++++++++++++++++++++++++++++++++ cmd/lncli/main.go | 1 + 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fd8f10ad7..41fabbfcc 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ ESCPKG := github.com\/lightningnetwork\/lnd MOBILE_PKG := $(PKG)/mobile TOOLS_DIR := tools +PREFIX ?= /usr/local + BTCD_PKG := github.com/btcsuite/btcd GOACC_PKG := github.com/ory/go-acc GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports @@ -122,12 +124,20 @@ build-itest-race: @$(call print, "Building itest binary for ${backend} backend.") CGO_ENABLED=0 $(GOTEST) -v ./itest -tags="$(DEV_TAGS) $(RPC_TAGS) integration $(backend)" -c -o itest/itest.test$(EXEC_SUFFIX) -#? install: Build and install lnd and lncli binaries, place them in $GOPATH/bin -install: +#? install-binaries: Build and install lnd and lncli binaries, place them in $GOPATH/bin +install-binaries: @$(call print, "Installing lnd and lncli.") $(GOINSTALL) -tags="${tags}" -ldflags="$(RELEASE_LDFLAGS)" $(PKG)/cmd/lnd $(GOINSTALL) -tags="${tags}" -ldflags="$(RELEASE_LDFLAGS)" $(PKG)/cmd/lncli +#? manpages: generate and install man pages +manpages: + @$(call print, "Generating man pages lncli.1 and lnd.1.") + ./scripts/gen_man_pages.sh $(DESTDIR) $(PREFIX) + +#? install: Build and install lnd and lncli binaries, place them in $GOPATH/bin, generate and install man pages +install: install-binaries manpages + #? release-install: Build and install lnd and lncli release binaries, place them in $GOPATH/bin release-install: @$(call print, "Installing release lnd and lncli.") diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 5190cd69f..8f397364f 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -18,6 +18,8 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" + "github.com/jessevdk/go-flags" + "github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/routing" "github.com/lightningnetwork/lnd/routing/route" @@ -1410,6 +1412,41 @@ func channelBalance(ctx *cli.Context) error { return nil } +var generateManPageCommand = cli.Command{ + Name: "generatemanpage", + Usage: "Generates a man page for lncli and lnd as " + + "lncli.1 and lnd.1 respectively.", + Hidden: true, + Action: actionDecorator(generateManPage), +} + +func generateManPage(ctx *cli.Context) error { + // Generate the man pages for lncli as lncli.1. + manpages, err := ctx.App.ToMan() + if err != nil { + return err + } + err = os.WriteFile("lncli.1", []byte(manpages), 0644) + if err != nil { + return err + } + + // Generate the man pages for lnd as lnd.1. + config := lnd.DefaultConfig() + fileParser := flags.NewParser(&config, flags.Default) + fileParser.Name = "lnd" + + var buf bytes.Buffer + fileParser.WriteManPage(&buf) + + err = os.WriteFile("lnd.1", buf.Bytes(), 0644) + if err != nil { + return err + } + + return nil +} + var getInfoCommand = cli.Command{ Name: "getinfo", Usage: "Returns basic information related to the active daemon.", diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index e956dbf91..95f82b234 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -508,6 +508,7 @@ func main() { fishCompletionCommand, listAliasesCommand, estimateRouteFeeCommand, + generateManPageCommand, } // Add any extra commands determined by build flags. From fb5b425c40e16fe4e1f966d1e1a04b67316e1232 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Sat, 9 Mar 2024 23:52:19 +0200 Subject: [PATCH 3/3] docs: update release-notes-0.18.0 --- docs/release-notes/release-notes-0.18.0.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/release-notes/release-notes-0.18.0.md b/docs/release-notes/release-notes-0.18.0.md index ed485af77..f5779acf0 100644 --- a/docs/release-notes/release-notes-0.18.0.md +++ b/docs/release-notes/release-notes-0.18.0.md @@ -194,6 +194,10 @@ * The [`closeallchannels` command now asks for confirmation before closing all channels](https://github.com/lightningnetwork/lnd/pull/8526). +* [Man pages](https://github.com/lightningnetwork/lnd/pull/8525) Generate man + pages automatically using `lncli generatemanpage` command for both `lncli` + and `lnd` commands when running `make install` in the Makefile. + # Improvements ## Functional Updates ### Tlv @@ -365,6 +369,7 @@ * Keagan McClelland * Marcos Fernandez Perez * Matt Morehouse +* Mohamed Awnallah * Ononiwu Maureen Chiamaka * Slyghtning * Tee8z