Merge pull request #3648 from crosbymichael/man-bin
Move manpage gen to separate binary
This commit is contained in:
		
							
								
								
									
										7
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								Makefile
									
									
									
									
									
								
							@@ -82,7 +82,6 @@ TEST_REQUIRES_ROOT_PACKAGES=$(filter \
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Project binaries.
 | 
					# Project binaries.
 | 
				
			||||||
COMMANDS=ctr containerd containerd-stress
 | 
					COMMANDS=ctr containerd containerd-stress
 | 
				
			||||||
MANBINARIES=ctr containerd containerd-stress
 | 
					 | 
				
			||||||
MANPAGES=ctr.1 containerd.1 containerd-config.1 containerd-config.toml.5
 | 
					MANPAGES=ctr.1 containerd.1 containerd-config.1 containerd-config.toml.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ifdef BUILDTAGS
 | 
					ifdef BUILDTAGS
 | 
				
			||||||
@@ -204,10 +203,8 @@ man: mandir $(addprefix man/,$(MANPAGES))
 | 
				
			|||||||
mandir:
 | 
					mandir:
 | 
				
			||||||
	@mkdir -p man
 | 
						@mkdir -p man
 | 
				
			||||||
 | 
					
 | 
				
			||||||
genman: $(addprefix genman/,$(MANBINARIES))
 | 
					genman: FORCE
 | 
				
			||||||
 | 
						go run cmd/gen-manpages/main.go man/
 | 
				
			||||||
genman/%: bin/% FORCE
 | 
					 | 
				
			||||||
	"$<" gen-man --format man man/
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
man/%: docs/man/%.md FORCE
 | 
					man/%: docs/man/%.md FORCE
 | 
				
			||||||
	@echo "$(WHALE) $<"
 | 
						@echo "$(WHALE) $<"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,6 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"github.com/containerd/containerd"
 | 
						"github.com/containerd/containerd"
 | 
				
			||||||
	"github.com/containerd/containerd/namespaces"
 | 
						"github.com/containerd/containerd/namespaces"
 | 
				
			||||||
	"github.com/containerd/containerd/pkg/climan"
 | 
					 | 
				
			||||||
	"github.com/containerd/containerd/plugin"
 | 
						"github.com/containerd/containerd/plugin"
 | 
				
			||||||
	metrics "github.com/docker/go-metrics"
 | 
						metrics "github.com/docker/go-metrics"
 | 
				
			||||||
	"github.com/sirupsen/logrus"
 | 
						"github.com/sirupsen/logrus"
 | 
				
			||||||
@@ -162,7 +161,6 @@ func main() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	app.Commands = []cli.Command{
 | 
						app.Commands = []cli.Command{
 | 
				
			||||||
		densityCommand,
 | 
							densityCommand,
 | 
				
			||||||
		climan.Command,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	app.Action = func(context *cli.Context) error {
 | 
						app.Action = func(context *cli.Context) error {
 | 
				
			||||||
		config := config{
 | 
							config := config{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,7 +21,6 @@ import (
 | 
				
			|||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/containerd/containerd/cmd/containerd/command"
 | 
						"github.com/containerd/containerd/cmd/containerd/command"
 | 
				
			||||||
	"github.com/containerd/containerd/pkg/climan"
 | 
					 | 
				
			||||||
	"github.com/containerd/containerd/pkg/seed"
 | 
						"github.com/containerd/containerd/pkg/seed"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -31,7 +30,6 @@ func init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	app := command.App()
 | 
						app := command.App()
 | 
				
			||||||
	app.Commands = append(app.Commands, climan.Command)
 | 
					 | 
				
			||||||
	if err := app.Run(os.Args); err != nil {
 | 
						if err := app.Run(os.Args); err != nil {
 | 
				
			||||||
		fmt.Fprintf(os.Stderr, "containerd: %s\n", err)
 | 
							fmt.Fprintf(os.Stderr, "containerd: %s\n", err)
 | 
				
			||||||
		os.Exit(1)
 | 
							os.Exit(1)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,7 +21,6 @@ import (
 | 
				
			|||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/containerd/containerd/cmd/ctr/app"
 | 
						"github.com/containerd/containerd/cmd/ctr/app"
 | 
				
			||||||
	"github.com/containerd/containerd/pkg/climan"
 | 
					 | 
				
			||||||
	"github.com/containerd/containerd/pkg/seed"
 | 
						"github.com/containerd/containerd/pkg/seed"
 | 
				
			||||||
	"github.com/urfave/cli"
 | 
						"github.com/urfave/cli"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -35,7 +34,6 @@ func init() {
 | 
				
			|||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	app := app.New()
 | 
						app := app.New()
 | 
				
			||||||
	app.Commands = append(app.Commands, pluginCmds...)
 | 
						app.Commands = append(app.Commands, pluginCmds...)
 | 
				
			||||||
	app.Commands = append(app.Commands, climan.Command)
 | 
					 | 
				
			||||||
	if err := app.Run(os.Args); err != nil {
 | 
						if err := app.Run(os.Args); err != nil {
 | 
				
			||||||
		fmt.Fprintf(os.Stderr, "ctr: %s\n", err)
 | 
							fmt.Fprintf(os.Stderr, "ctr: %s\n", err)
 | 
				
			||||||
		os.Exit(1)
 | 
							os.Exit(1)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										57
									
								
								cmd/gen-manpages/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								cmd/gen-manpages/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -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
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user