Lasa is a stateless proxy that generates a RSS or an Atom feed from a Standard.site publication. lasa.anhgelus.world
rss atom atprotocol standard-site atproto
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(cli): generalize commands for printing

+65 -44
+7
cmd/internal/command.go
··· 1 + package internal 2 + 3 + type Command struct { 4 + Name string 5 + Usage string 6 + Callback func([]string) 7 + }
+37
cmd/internal/print.go
··· 1 + package internal 2 + 3 + import ( 4 + "flag" 5 + "fmt" 6 + "os" 7 + "text/tabwriter" 8 + ) 9 + 10 + func Usage(syntax, usage string, commands []Command, flags *flag.FlagSet, examples []string) { 11 + fmt.Println("Usage:", syntax) 12 + fmt.Println(usage) 13 + w := tabwriter.NewWriter(os.Stdout, 0, 2, 1, ' ', 0) 14 + if commands != nil { 15 + fmt.Fprintln(w) 16 + fmt.Fprintln(w, "Commands:") 17 + for _, c := range commands { 18 + fmt.Fprintln(w, "\t", c.Name, "\t-\t", c.Usage) 19 + } 20 + } 21 + if flags != nil { 22 + fmt.Fprintln(w) 23 + fmt.Fprintln(w, "Options:") 24 + flags.VisitAll(func(f *flag.Flag) { 25 + fmt.Fprintln(w, "\t-", f.Name, "\t", f.Usage, "\t(default:", f.DefValue, ")") 26 + }) 27 + } 28 + fmt.Fprintln(w) 29 + fmt.Fprintln(w, "Examples:") 30 + for _, s := range examples { 31 + fmt.Fprintln(w, "\t", s) 32 + } 33 + err := w.Flush() 34 + if err != nil { 35 + panic(err) 36 + } 37 + }
+21 -12
cmd/lasa/main.go
··· 2 2 3 3 import ( 4 4 "flag" 5 + 6 + "tangled.org/anhgelus.world/lasa/cmd/internal" 5 7 ) 6 8 7 9 var ( ··· 12 14 flag.BoolVar(&help, "h", false, "show the help") 13 15 } 14 16 17 + var commands = []internal.Command{ 18 + {Name: "publication", Usage: "works with publication", Callback: handlePublication}, 19 + } 20 + 15 21 func main() { 16 22 flag.Parse() 17 23 args := flag.Args() ··· 24 30 if len(args) > 1 { 25 31 next = args[1:] 26 32 } 27 - switch command { 28 - case "help": 29 - handleHelp() 30 - case "publication": 31 - handlePublication(next) 33 + for _, c := range commands { 34 + if c.Name == command { 35 + c.Callback(next) 36 + return 37 + } 32 38 } 39 + handleHelp() 33 40 } 34 41 35 42 func handleHelp() { 36 - usage( 43 + internal.Usage( 37 44 `lasa <command>`, 38 45 `Lasa is a CLI tool.`, 46 + commands, 47 + nil, 39 48 []string{ 40 - "lasa publication\t-\tworks with publication", 49 + "lasa publication anhgelus.world\t-\tdisplay publications of anhgelus.world", 41 50 }, 42 - nil, 43 - )() 51 + ) 44 52 } 45 53 46 54 func handlePublication(args []string) { 47 55 if len(args) == 0 { 48 - usage( 56 + internal.Usage( 49 57 `lasa publication <identifier> [rkey]`, 50 58 `List publications of identifier (can be a DID or an Handle) or display a specific publication referenced by its rkey`, 59 + nil, 60 + nil, 51 61 []string{ 52 62 "lasa publication anhgelus.world\t-\tdisplay publications of anhgelus.world", 53 63 "lasa publication did:plc:123\t-\tdisplay publications of did:plc:123", 54 64 "lasa publication did:web:example.org fooBar\t-\tdisplay publication of did:web:example.org referenced by fooBar", 55 65 }, 56 - nil, 57 - )() 66 + ) 58 67 return 59 68 } 60 69 }
-32
cmd/lasa/print.go
··· 1 - package main 2 - 3 - import ( 4 - "flag" 5 - "fmt" 6 - "os" 7 - "text/tabwriter" 8 - ) 9 - 10 - func usage(syntax, usage string, examples []string, flags *flag.FlagSet) func() { 11 - return func() { 12 - fmt.Println("Usage:", syntax) 13 - fmt.Println(usage) 14 - w := tabwriter.NewWriter(os.Stdout, 0, 2, 1, ' ', 0) 15 - if flags != nil { 16 - fmt.Fprintln(w) 17 - fmt.Fprintln(w, "Options:") 18 - flags.VisitAll(func(f *flag.Flag) { 19 - fmt.Fprintln(w, "\t-", f.Name, "\t", f.Usage, "\t(default:", f.DefValue, ")") 20 - }) 21 - } 22 - fmt.Fprintln(w) 23 - fmt.Fprintln(w, "Examples:") 24 - for _, s := range examples { 25 - fmt.Fprintln(w, "\t", s) 26 - } 27 - err := w.Flush() 28 - if err != nil { 29 - panic(err) 30 - } 31 - } 32 - }