diff --git a/Makefile b/Makefile index 487f6954e..1e5fc465f 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,6 @@ 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 @@ -204,10 +203,8 @@ man: mandir $(addprefix man/,$(MANPAGES)) mandir: @mkdir -p man -genman: $(addprefix genman/,$(MANBINARIES)) - -genman/%: bin/% FORCE - "$<" gen-man --format man man/ +genman: FORCE + go run cmd/gen-manpages/main.go man/ man/%: docs/man/%.md FORCE @echo "$(WHALE) $<" diff --git a/cmd/containerd-stress/main.go b/cmd/containerd-stress/main.go index b842df333..9ef058b90 100644 --- a/cmd/containerd-stress/main.go +++ b/cmd/containerd-stress/main.go @@ -30,7 +30,6 @@ 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" @@ -162,7 +161,6 @@ func main() { } app.Commands = []cli.Command{ densityCommand, - climan.Command, } app.Action = func(context *cli.Context) error { config := config{ diff --git a/cmd/containerd/main.go b/cmd/containerd/main.go index d258c9500..10bde45bd 100644 --- a/cmd/containerd/main.go +++ b/cmd/containerd/main.go @@ -21,7 +21,6 @@ import ( "os" "github.com/containerd/containerd/cmd/containerd/command" - "github.com/containerd/containerd/pkg/climan" "github.com/containerd/containerd/pkg/seed" ) @@ -31,7 +30,6 @@ 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) diff --git a/cmd/ctr/main.go b/cmd/ctr/main.go index 9db84d22d..cf72de28e 100644 --- a/cmd/ctr/main.go +++ b/cmd/ctr/main.go @@ -21,7 +21,6 @@ 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" ) @@ -35,7 +34,6 @@ 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) diff --git a/cmd/gen-manpages/main.go b/cmd/gen-manpages/main.go new file mode 100644 index 000000000..610dd3ddb --- /dev/null +++ b/cmd/gen-manpages/main.go @@ -0,0 +1,57 @@ +/* + 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 main + +import ( + "flag" + "fmt" + "io/ioutil" + "os" + "path/filepath" + + "github.com/containerd/containerd/cmd/containerd/command" + "github.com/containerd/containerd/cmd/ctr/app" + "github.com/urfave/cli" +) + +func main() { + if err := run(); err != nil { + fmt.Fprint(os.Stderr, err) + os.Exit(1) + } +} + +func run() error { + flag.Parse() + apps := map[string]*cli.App{ + "containerd": command.App(), + "ctr": app.New(), + } + dir := flag.Arg(0) + for name, app := range apps { + // clear out the usage as we use banners that do not display in man pages + app.Usage = "" + data, err := app.ToMan() + if err != nil { + return err + } + if err := ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("%s.1", name)), []byte(data), 0644); err != nil { + return err + } + } + return nil +} diff --git a/pkg/climan/cli.go b/pkg/climan/cli.go deleted file mode 100644 index 4302b28a3..000000000 --- a/pkg/climan/cli.go +++ /dev/null @@ -1,75 +0,0 @@ -/* - 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 -}