Skip to content

Commit d3ccbc6

Browse files
authored
Merge pull request containerd#3637 from crosbymichael/manpages
Use updated urfave/cli to generate man pages
2 parents d8ad1bd + f3a5b8c commit d3ccbc6

40 files changed

+2811
-1596
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ run:
1919
- api
2020
- design
2121
- docs
22+
- docs/man

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ TEST_REQUIRES_ROOT_PACKAGES=$(filter \
8282

8383
# Project binaries.
8484
COMMANDS=ctr containerd containerd-stress
85+
MANBINARIES=ctr containerd containerd-stress
8586
MANPAGES=ctr.1 containerd.1 containerd-config.1 containerd-config.toml.5
8687

8788
ifdef BUILDTAGS
@@ -114,7 +115,7 @@ BINARIES=$(addprefix bin/,$(COMMANDS))
114115
TESTFLAGS ?= $(TESTFLAGS_RACE)
115116
TESTFLAGS_PARALLEL ?= 8
116117

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

120121
all: binaries
@@ -203,6 +204,11 @@ man: mandir $(addprefix man/,$(MANPAGES))
203204
mandir:
204205
@mkdir -p man
205206

207+
genman: $(addprefix genman/,$(MANBINARIES))
208+
209+
genman/%: bin/% FORCE
210+
"$<" gen-man --format man man/
211+
206212
man/%: docs/man/%.md FORCE
207213
@echo "$(WHALE) $<"
208214
go-md2man -in "$<" -out "$@"

cmd/containerd-stress/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/containerd/containerd"
3232
"github.com/containerd/containerd/namespaces"
33+
"github.com/containerd/containerd/pkg/climan"
3334
"github.com/containerd/containerd/plugin"
3435
metrics "github.com/docker/go-metrics"
3536
"github.com/sirupsen/logrus"
@@ -161,6 +162,7 @@ func main() {
161162
}
162163
app.Commands = []cli.Command{
163164
densityCommand,
165+
climan.Command,
164166
}
165167
app.Action = func(context *cli.Context) error {
166168
config := config{

cmd/containerd/command/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ func App() *cli.App {
7070
app.Name = "containerd"
7171
app.Version = version.Version
7272
app.Usage = usage
73+
app.Description = `
74+
containerd is a high performance container runtime whose daemon can be started
75+
by using this command. If none of the *config*, *publish*, or *help* commands
76+
are specified, the default action of the **containerd** command is to start the
77+
containerd daemon in the foreground.
78+
79+
80+
A default configuration is used if no TOML configuration is specified or located
81+
at the default file location. The *containerd config* command can be used to
82+
generate the default configuration for containerd. The output of that command
83+
can be used and modified as necessary as a custom configuration.`
7384
app.Flags = []cli.Flag{
7485
cli.StringFlag{
7586
Name: "config,c",

cmd/containerd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222

2323
"github.com/containerd/containerd/cmd/containerd/command"
24+
"github.com/containerd/containerd/pkg/climan"
2425
"github.com/containerd/containerd/pkg/seed"
2526
)
2627

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

3132
func main() {
3233
app := command.App()
34+
app.Commands = append(app.Commands, climan.Command)
3335
if err := app.Run(os.Args); err != nil {
3436
fmt.Fprintf(os.Stderr, "containerd: %s\n", err)
3537
os.Exit(1)

cmd/ctr/app/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func New() *cli.App {
5757
app := cli.NewApp()
5858
app.Name = "ctr"
5959
app.Version = version.Version
60+
app.Description = `
61+
ctr is an unsupported debug and administrative client for interacting
62+
with the containerd daemon. Because it is unsupported, the commands,
63+
options, and operations are not guaranteed to be backward compatible or
64+
stable from release to release of the containerd project.`
6065
app.Usage = `
6166
__
6267
_____/ /______

cmd/ctr/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222

2323
"github.com/containerd/containerd/cmd/ctr/app"
24+
"github.com/containerd/containerd/pkg/climan"
2425
"github.com/containerd/containerd/pkg/seed"
2526
"github.com/urfave/cli"
2627
)
@@ -34,6 +35,7 @@ func init() {
3435
func main() {
3536
app := app.New()
3637
app.Commands = append(app.Commands, pluginCmds...)
38+
app.Commands = append(app.Commands, climan.Command)
3739
if err := app.Run(os.Args); err != nil {
3840
fmt.Fprintf(os.Stderr, "ctr: %s\n", err)
3941
os.Exit(1)

docs/man/containerd.1.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

docs/man/ctr.1.md

Lines changed: 0 additions & 98 deletions
This file was deleted.

pkg/climan/cli.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package climan
18+
19+
import (
20+
"fmt"
21+
"io/ioutil"
22+
"path/filepath"
23+
24+
"github.com/pkg/errors"
25+
"github.com/urfave/cli"
26+
)
27+
28+
var Command = cli.Command{
29+
Name: "gen-man",
30+
Usage: "generate man pages for the cli application",
31+
Hidden: true,
32+
Flags: []cli.Flag{
33+
cli.StringFlag{
34+
Name: "format,f",
35+
Usage: "specify the format in (md:man)",
36+
Value: "md",
37+
},
38+
cli.IntFlag{
39+
Name: "section,s",
40+
Usage: "section of the man pages",
41+
Value: 1,
42+
},
43+
},
44+
Action: func(clix *cli.Context) (err error) {
45+
// clear out the usage as we use banners that do not display in man pages
46+
clix.App.Usage = ""
47+
dir := clix.Args().First()
48+
if dir == "" {
49+
return errors.New("directory argument is required")
50+
}
51+
var (
52+
data string
53+
ext string
54+
)
55+
switch clix.String("format") {
56+
case "man":
57+
data, err = clix.App.ToMan()
58+
default:
59+
data, err = clix.App.ToMarkdown()
60+
ext = "md"
61+
}
62+
if err != nil {
63+
return err
64+
}
65+
return ioutil.WriteFile(filepath.Join(dir, formatFilename(clix, clix.Int("section"), ext)), []byte(data), 0644)
66+
},
67+
}
68+
69+
func formatFilename(clix *cli.Context, section int, ext string) string {
70+
s := fmt.Sprintf("%s.%d", clix.App.Name, section)
71+
if ext != "" {
72+
s += "." + ext
73+
}
74+
return s
75+
}

0 commit comments

Comments
 (0)