11package man
22
33import (
4+ "embed"
45 "fmt"
56 "io/fs"
67 "log/slog"
@@ -120,15 +121,8 @@ func (m Manual) GetCommand(cmd string, opts ...CommandOpts) *Doc {
120121}
121122
122123//nolint:mnd,gocritic // allow file separator counts to be hardcoded
123- func init () {
124- slog .Debug ("Loading docs from embed" )
125- Docs = Manual {
126- Docs : make (map [string ]* Doc ),
127- En : make (map [string ]* Doc ),
128- Fr : make (map [string ]* Doc ),
129- }
130-
131- err := fs .WalkDir (docsEmbed .ManFiles , "." , func (path string , d fs.DirEntry , err error ) error {
124+ func ProcessEmbeddedDocs (manFiles embed.FS ) {
125+ err := fs .WalkDir (manFiles , "." , func (path string , d fs.DirEntry , err error ) error {
132126 if err != nil {
133127 return err
134128 }
@@ -165,12 +159,12 @@ func init() {
165159 }
166160
167161 slog .Debug ("Found doc" , slog .String ("cmd" , cmd ), slog .String ("lang" , lang ))
168- c , err := docsEmbed . ManFiles .ReadFile (path )
162+ c , err := manFiles .ReadFile (path )
169163 if err != nil {
170164 return fmt .Errorf ("could not read file, %s: %s " , path , err .Error ())
171165 }
172166
173- doc , err := processDoc (string (c ))
167+ doc , err := ProcessDoc (string (c ))
174168 if err != nil {
175169 return fmt .Errorf ("could not process doc, %s: %s" , path , err .Error ())
176170 }
@@ -192,7 +186,18 @@ func init() {
192186 }
193187}
194188
195- func processDoc (doc string ) (* Doc , error ) {
189+ func init () {
190+ slog .Debug ("Loading docs from embed" )
191+ Docs = Manual {
192+ Docs : make (map [string ]* Doc ),
193+ En : make (map [string ]* Doc ),
194+ Fr : make (map [string ]* Doc ),
195+ }
196+
197+ ProcessEmbeddedDocs (docsEmbed .ManFiles )
198+ }
199+
200+ func ProcessDoc (doc string ) (* Doc , error ) {
196201 if len (doc ) == 0 {
197202 return nil , fmt .Errorf ("empty document" )
198203 }
0 commit comments