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

chore: Utility for generation of man pages #493

Merged
merged 2 commits into from
Jun 19, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
cli/defradb/defradb
cli/defradb/defradb.exe
build/defradb*
build/*
cover.out
coverage-full.txt
coverage-quick.txt
Expand Down
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ 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/
go run cmd/genclidocs/genclidocs.go -o docs/cli/

.PHONY: docs\:manpages
docs\:manpages:
go run cmd/genmanpages/main.go -o build/man/

detectedOS := $(shell uname)
.PHONY: install\:manpages
install\:manpages:
ifeq ($(detectedOS),Linux)
cp build/man/* /usr/share/man/man1/
endif
ifneq ($(detectedOS),Linux)
@echo "Direct installation of Defradb's man pages is not supported on your system."
endif
51 changes: 51 additions & 0 deletions cmd/genmanpages/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}