1 Commits
v1.1 ... v1.2

Author SHA1 Message Date
Alex Schroeder
e231412bdb Add list command 2023-12-09 09:21:24 +01:00
2 changed files with 41 additions and 0 deletions

40
list_cmd.go Normal file
View File

@@ -0,0 +1,40 @@
package main
import (
"context"
"flag"
"fmt"
"github.com/google/subcommands"
"io"
"os"
)
type listCmd struct {
}
func (cmd *listCmd) SetFlags(f *flag.FlagSet) {
}
func (*listCmd) Name() string { return "list" }
func (*listCmd) Synopsis() string { return "List pages with name and title." }
func (*listCmd) Usage() string {
return `list:
List all pages with name and title, separated by a tabulator.
`
}
func (cmd *listCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
return listCli(os.Stdout, f.Args())
}
// listCli runs the list command on the command line. It is used
// here with an io.Writer for easy testing.
func listCli(w io.Writer, args []string) subcommands.ExitStatus {
index.load()
index.RLock()
defer index.RUnlock()
for name, title := range index.titles {
fmt.Fprintf(w, "%s\t%s\n", name, title)
}
return subcommands.ExitSuccess
}

View File

@@ -126,6 +126,7 @@ func commands() {
subcommands.Register(subcommands.FlagsCommand(), "")
subcommands.Register(subcommands.CommandsCommand(), "")
subcommands.Register(&htmlCmd{}, "")
subcommands.Register(&listCmd{}, "")
subcommands.Register(&staticCmd{}, "")
subcommands.Register(&searchCmd{}, "")
subcommands.Register(&replaceCmd{}, "")