From ad34fbed2cea739f9fd440b5ffb83bc2fb68cb47 Mon Sep 17 00:00:00 2001 From: Orpheus Lummis Date: Fri, 10 Jun 2022 10:44:05 -0500 Subject: [PATCH 1/2] feat: Add utility for generation of man pages --- .gitignore | 4 +--- Makefile | 29 ++++++++++++++++++++++- cmd/genmanpages/main.go | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 cmd/genmanpages/main.go diff --git a/.gitignore b/.gitignore index 6581832611..0b51a211e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -cli/defradb/defradb -cli/defradb/defradb.exe -build/defradb* +build/* cover.out coverage-full.txt coverage-quick.txt diff --git a/Makefile b/Makefile index 1cc4a0bce9..12a4fcde0f 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,33 @@ lint\:list: chglog: git-chglog -c "tools/configs/chglog/config.yml" --next-tag v0.x.0 -o CHANGELOG.md +.PHONY: docs +docs: + make docs\:cli + make docs\:manpages + .PHONY: docs\:cli docs\:cli: - go run cmd/genclidocs/genclidocs.go -o docs/cli/ \ No newline at end of file + go run cmd/genclidocs/genclidocs.go -o docs/cli/ + +.PHONY: docs\:manpages +docs\:manpages: + go run cmd/genmanpages/main.go -o build/man/ + +ifeq ($(OS),Windows_NT) +detectedOS := "Windows" +else +detectedOS := $(shell uname) +endif + +.PHONY: install\:manpages +install\:manpages: docs\:manpages +ifeq ($(detectedOS),Linux) + cp build/man/* /usr/share/man/man1/ +endif +ifeq ($(detectedOS),Darwin) + @echo "Installation of man pages is not supported on macOS." +endif +ifeq ($(detectedOS),Windows) + @echo "Installation of man pages is not supported on Windows." +endif \ No newline at end of file diff --git a/cmd/genmanpages/main.go b/cmd/genmanpages/main.go new file mode 100644 index 0000000000..4484d2578d --- /dev/null +++ b/cmd/genmanpages/main.go @@ -0,0 +1,51 @@ +// Copyright 2022 Democratized Data Foundation +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +/* +genmanpages handles the generation of man pages. It is meant to be used as part of packaging scripts, as man pages +installation is packaging and system dependent. +*/ +package main + +import ( + "context" + "flag" + "os" + + "github.com/sourcenetwork/defradb/cli" + "github.com/sourcenetwork/defradb/logging" + "github.com/spf13/cobra/doc" +) + +const defaultPerm os.FileMode = 0o777 + +var log = logging.MustNewLogger("defra.genmanpages") + +func main() { + dirFlag := flag.String("o", "build/man", "Directory in which to generate DefraDB man pages") + flag.Parse() + genRootManPages(*dirFlag) +} + +func genRootManPages(dir string) { + ctx := context.Background() + header := &doc.GenManHeader{ + Title: "defradb - Peer-to-Peer Edge Database", + Section: "1", + } + err := os.MkdirAll(dir, defaultPerm) + if err != nil { + log.FatalE(ctx, "Failed to create directory", err, logging.NewKV("dir", dir)) + } + err = doc.GenManTree(cli.RootCmd, header, dir) + if err != nil { + log.FatalE(ctx, "Failed generation of man pages", err) + } +} From c9c7860b4acdee92934d940162a0d61b0c922687 Mon Sep 17 00:00:00 2001 From: Orpheus Lummis Date: Fri, 10 Jun 2022 11:31:46 -0500 Subject: [PATCH 2/2] Linux-only install --- Makefile | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 12a4fcde0f..cd7e7eb040 100644 --- a/Makefile +++ b/Makefile @@ -159,20 +159,12 @@ docs\:cli: docs\:manpages: go run cmd/genmanpages/main.go -o build/man/ -ifeq ($(OS),Windows_NT) -detectedOS := "Windows" -else detectedOS := $(shell uname) -endif - .PHONY: install\:manpages -install\:manpages: docs\:manpages +install\:manpages: ifeq ($(detectedOS),Linux) cp build/man/* /usr/share/man/man1/ endif -ifeq ($(detectedOS),Darwin) - @echo "Installation of man pages is not supported on macOS." -endif -ifeq ($(detectedOS),Windows) - @echo "Installation of man pages is not supported on Windows." +ifneq ($(detectedOS),Linux) + @echo "Direct installation of Defradb's man pages is not supported on your system." endif \ No newline at end of file