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 updated urfave/cli to generate man pages #3637

Merged
merged 1 commit into from Sep 11, 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
1 change: 1 addition & 0 deletions .golangci.yml
Expand Up @@ -19,3 +19,4 @@ run:
- api
- design
- docs
- docs/man
8 changes: 7 additions & 1 deletion Makefile
Expand Up @@ -82,6 +82,7 @@ TEST_REQUIRES_ROOT_PACKAGES=$(filter \

# Project binaries.
COMMANDS=ctr containerd containerd-stress
MANBINARIES=ctr containerd containerd-stress
MANPAGES=ctr.1 containerd.1 containerd-config.1 containerd-config.toml.5

ifdef BUILDTAGS
Expand Down Expand Up @@ -114,7 +115,7 @@ BINARIES=$(addprefix bin/,$(COMMANDS))
TESTFLAGS ?= $(TESTFLAGS_RACE)
TESTFLAGS_PARALLEL ?= 8

.PHONY: clean all AUTHORS build binaries test integration generate protos checkprotos coverage ci check help install uninstall vendor release mandir install-man
.PHONY: clean all AUTHORS build binaries test integration generate protos checkprotos coverage ci check help install uninstall vendor release mandir install-man genman
.DEFAULT: default

all: binaries
Expand Down Expand Up @@ -203,6 +204,11 @@ man: mandir $(addprefix man/,$(MANPAGES))
mandir:
@mkdir -p man

genman: $(addprefix genman/,$(MANBINARIES))

genman/%: bin/% FORCE
"$<" gen-man --format man man/

man/%: docs/man/%.md FORCE
@echo "$(WHALE) $<"
go-md2man -in "$<" -out "$@"
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd-stress/main.go
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/climan"
"github.com/containerd/containerd/plugin"
metrics "github.com/docker/go-metrics"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -161,6 +162,7 @@ func main() {
}
app.Commands = []cli.Command{
densityCommand,
climan.Command,
}
app.Action = func(context *cli.Context) error {
config := config{
Expand Down
11 changes: 11 additions & 0 deletions cmd/containerd/command/main.go
Expand Up @@ -70,6 +70,17 @@ func App() *cli.App {
app.Name = "containerd"
app.Version = version.Version
app.Usage = usage
app.Description = `
containerd is a high performance container runtime whose daemon can be started
by using this command. If none of the *config*, *publish*, or *help* commands
are specified, the default action of the **containerd** command is to start the
containerd daemon in the foreground.


A default configuration is used if no TOML configuration is specified or located
at the default file location. The *containerd config* command can be used to
generate the default configuration for containerd. The output of that command
can be used and modified as necessary as a custom configuration.`
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config,c",
Expand Down
2 changes: 2 additions & 0 deletions cmd/containerd/main.go
Expand Up @@ -21,6 +21,7 @@ import (
"os"

"github.com/containerd/containerd/cmd/containerd/command"
"github.com/containerd/containerd/pkg/climan"
"github.com/containerd/containerd/pkg/seed"
)

Expand All @@ -30,6 +31,7 @@ func init() {

func main() {
app := command.App()
app.Commands = append(app.Commands, climan.Command)
if err := app.Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "containerd: %s\n", err)
os.Exit(1)
Expand Down
5 changes: 5 additions & 0 deletions cmd/ctr/app/main.go
Expand Up @@ -57,6 +57,11 @@ func New() *cli.App {
app := cli.NewApp()
app.Name = "ctr"
app.Version = version.Version
app.Description = `
ctr is an unsupported debug and administrative client for interacting
with the containerd daemon. Because it is unsupported, the commands,
options, and operations are not guaranteed to be backward compatible or
stable from release to release of the containerd project.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the same description to containerd-stress?

app.Usage = `
__
_____/ /______
Expand Down
2 changes: 2 additions & 0 deletions cmd/ctr/main.go
Expand Up @@ -21,6 +21,7 @@ import (
"os"

"github.com/containerd/containerd/cmd/ctr/app"
"github.com/containerd/containerd/pkg/climan"
"github.com/containerd/containerd/pkg/seed"
"github.com/urfave/cli"
)
Expand All @@ -34,6 +35,7 @@ func init() {
func main() {
app := app.New()
app.Commands = append(app.Commands, pluginCmds...)
app.Commands = append(app.Commands, climan.Command)
if err := app.Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "ctr: %s\n", err)
os.Exit(1)
Expand Down
61 changes: 0 additions & 61 deletions docs/man/containerd.1.md

This file was deleted.

98 changes: 0 additions & 98 deletions docs/man/ctr.1.md

This file was deleted.

75 changes: 75 additions & 0 deletions pkg/climan/cli.go
@@ -0,0 +1,75 @@
/*
Copyright The containerd Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package climan

import (
"fmt"
"io/ioutil"
"path/filepath"

"github.com/pkg/errors"
"github.com/urfave/cli"
)

var Command = cli.Command{
Name: "gen-man",
Usage: "generate man pages for the cli application",
Hidden: true,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format,f",
Usage: "specify the format in (md:man)",
Value: "md",
},
cli.IntFlag{
Name: "section,s",
Usage: "section of the man pages",
Value: 1,
},
},
Action: func(clix *cli.Context) (err error) {
// clear out the usage as we use banners that do not display in man pages
clix.App.Usage = ""
dir := clix.Args().First()
if dir == "" {
return errors.New("directory argument is required")
}
var (
data string
ext string
)
switch clix.String("format") {
case "man":
data, err = clix.App.ToMan()
default:
data, err = clix.App.ToMarkdown()
ext = "md"
}
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(dir, formatFilename(clix, clix.Int("section"), ext)), []byte(data), 0644)
},
}

func formatFilename(clix *cli.Context, section int, ext string) string {
s := fmt.Sprintf("%s.%d", clix.App.Name, section)
if ext != "" {
s += "." + ext
}
return s
}
2 changes: 1 addition & 1 deletion vendor.conf
Expand Up @@ -23,7 +23,7 @@ github.com/opencontainers/runtime-spec 29686dbc5559d93fb1ef402eeda3e35c38d75af4
github.com/opencontainers/runc f4982d86f7fde0b6f953cc62ccc4022c519a10a9 # v1.0.0-rc8-32-gf4982d86
github.com/konsorten/go-windows-terminal-sequences v1.0.1
github.com/sirupsen/logrus v1.4.1
github.com/urfave/cli 7bc6a0acffa589f415f88aca16cc1de5ffd66f9c
github.com/urfave/cli 388c2dd0f4ffaa8541e371d49c8413870a04d9fe # v1.22.0 +
golang.org/x/net f3200d17e092c607f615320ecaad13d87ad9a2b3
google.golang.org/grpc 6eaf6f47437a6b4e2153a190160ef39a92c7eceb # v1.23.0
github.com/pkg/errors v0.8.1
Expand Down