Skip to content

Commit

Permalink
chore: Add utility for generation of man pages (sourcenetwork#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
orpheuslummis authored Jun 19, 2022
1 parent 17e99ec commit 1a3c9ca
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
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)
}
}

0 comments on commit 1a3c9ca

Please sign in to comment.