@@ -22,6 +22,7 @@ import (
2222 "io/ioutil"
2323 "os"
2424 "path/filepath"
25+ "strings"
2526
2627 "github.com/containerd/containerd/cmd/containerd/command"
2728 "github.com/containerd/containerd/cmd/ctr/app"
@@ -41,22 +42,28 @@ func run() error {
4142 "containerd" : command .App (),
4243 "ctr" : app .New (),
4344 }
44- name := flag .Arg (0 )
4545 dir := flag .Arg (1 )
46- app , ok := apps [name ]
46+
47+ parts := strings .SplitN (flag .Arg (0 ), "." , 2 )
48+ if len (parts ) != 2 {
49+ return fmt .Errorf ("invalid name '%s': name does not contain man page section" , flag .Arg (0 ))
50+ }
51+ name , section := parts [0 ], parts [1 ]
52+
53+ appName , ok := apps [name ]
4754 if ! ok {
48- return fmt .Errorf ("Invalid application '%s'" , name )
55+ return fmt .Errorf ("invalid application '%s'" , name )
4956 }
57+
5058 // clear out the usage as we use banners that do not display in man pages
51- app .Usage = ""
52- data , err := app .ToMan ()
59+ appName .Usage = ""
60+ appName .ToMan ()
61+ data , err := appName .ToMan ()
5362 if err != nil {
5463 return err
5564 }
56- if _ , err := os .Stat (dir ); os .IsNotExist (err ) {
57- os .Mkdir (dir , os .ModePerm )
58- }
59- if err := ioutil .WriteFile (filepath .Join (dir , fmt .Sprintf ("%s.1" , name )), []byte (data ), 0644 ); err != nil {
65+ _ = os .MkdirAll (dir , os .ModePerm )
66+ if err := ioutil .WriteFile (filepath .Join (dir , fmt .Sprintf ("%s.%s" , name , section )), []byte (data ), 0644 ); err != nil {
6067 return err
6168 }
6269 return nil
0 commit comments