| 92 | } |
| 93 | |
| 94 | func writeCommand(w io.Writer, cmd *serpent.Command) error { |
| 95 | var b strings.Builder |
| 96 | err := commandTemplate.Execute(&b, cmd) |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
| 100 | content := stripansi.Strip(b.String()) |
| 101 | |
| 102 | // Remove the version and its right space, since during this script running |
| 103 | // there is no build info available |
| 104 | content = strings.ReplaceAll(content, buildinfo.Version()+" ", "") |
| 105 | |
| 106 | // Remove references to the current working directory |
| 107 | cwd, err := os.Getwd() |
| 108 | if err != nil { |
| 109 | return err |
| 110 | } |
| 111 | content = strings.ReplaceAll(content, cwd, ".") |
| 112 | |
| 113 | homedir, err := os.UserHomeDir() |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | content = strings.ReplaceAll(content, homedir, "~") |
| 118 | |
| 119 | _, err = w.Write([]byte(content)) |
| 120 | return err |
| 121 | } |
| 122 | |
| 123 | func genTree(dir string, cmd *serpent.Command, wroteLog map[string]*serpent.Command) error { |
| 124 | if cmd.Hidden { |