11package main
22
33import (
4+ "bytes"
45 "compress/gzip"
56 "errors"
67 "io"
@@ -11,6 +12,7 @@ import (
1112 "time"
1213
1314 "github.com/gabe565/moreutils/cmd"
15+ "github.com/gabe565/moreutils/cmd/ifdata"
1416 "github.com/gabe565/moreutils/internal/cmdutil"
1517 "github.com/gabe565/moreutils/internal/cmdutil/subcommands"
1618 "github.com/gabe565/moreutils/internal/generate/seealsoreplacer"
@@ -83,6 +85,14 @@ func main() {
8385 w = seealsoreplacer .New (w , ".SH SEE ALSO\n " , linked )
8486 }
8587
88+ if subCmd .Name () == ifdata .Name {
89+ w = optionsInserter {
90+ w : w ,
91+ find : "help for " + ifdata .Name + "\n " ,
92+ insert : ifdata .ManOptions (),
93+ }
94+ }
95+
8696 if err := doc .GenMan (subCmd , & header , w ); err != nil {
8797 panic (err )
8898 }
@@ -97,3 +107,27 @@ func main() {
97107 }
98108 }
99109}
110+
111+ type optionsInserter struct {
112+ w io.Writer
113+ find string
114+ insert string
115+ }
116+
117+ func (o optionsInserter ) Write (p []byte ) (int , error ) {
118+ if ! strings .HasSuffix (o .insert , "\n " ) {
119+ o .insert += "\n "
120+ }
121+
122+ if bytes .Contains (p , []byte (o .find )) {
123+ beforeIdx := bytes .Index (p , []byte (o .find ))
124+ if beforeIdx == - 1 {
125+ panic ("missing header: " + o .find )
126+ }
127+ beforeIdx += len (o .find )
128+
129+ _ , err := o .w .Write (slices .Concat (p [:beforeIdx ], []byte (o .find ), []byte (o .insert ), p [beforeIdx :]))
130+ return len (p ), err
131+ }
132+ return o .w .Write (p )
133+ }
0 commit comments