man: move ctr.1, containerd-config to section 8, and fix generation

I missed this in my previous change: the ctr man page is also
in Section 8, because it's considered an administrative tool,
and containerd-config is related to containerd so updating these
as well.

This commit also fixes naming of the generated files, which was
hard-coded to .1.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2020-04-02 17:30:54 +02:00
parent 9ba5ea232c
commit ad090e67e9
4 changed files with 25 additions and 18 deletions

View File

@@ -22,6 +22,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/containerd/containerd/cmd/containerd/command"
"github.com/containerd/containerd/cmd/ctr/app"
@@ -41,22 +42,28 @@ func run() error {
"containerd": command.App(),
"ctr": app.New(),
}
name := flag.Arg(0)
dir := flag.Arg(1)
app, ok := apps[name]
if !ok {
return fmt.Errorf("Invalid application '%s'", name)
parts := strings.SplitN(flag.Arg(0), ".", 2)
if len(parts) != 2 {
return fmt.Errorf("invalid name '%s': name does not contain man page section", flag.Arg(0))
}
name, section := parts[0], parts[1]
appName, ok := apps[name]
if !ok {
return fmt.Errorf("invalid application '%s'", name)
}
// clear out the usage as we use banners that do not display in man pages
app.Usage = ""
data, err := app.ToMan()
appName.Usage = ""
appName.ToMan()
data, err := appName.ToMan()
if err != nil {
return err
}
if _, err := os.Stat(dir); os.IsNotExist(err) {
os.Mkdir(dir, os.ModePerm)
}
if err := ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("%s.1", name)), []byte(data), 0644); err != nil {
_ = os.MkdirAll(dir, os.ModePerm)
if err := ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("%s.%s", name, section)), []byte(data), 0644); err != nil {
return err
}
return nil