From e50122ce5dd4496061cb52c495d88f9efd98a3f8 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 11 Oct 2024 10:51:51 +0000 Subject: feat(yae): add listed output for update --- yae.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'yae.go') diff --git a/yae.go b/yae.go index 613ae2a..d7be200 100644 --- a/yae.go +++ b/yae.go @@ -165,9 +165,13 @@ func main() { Name: "show-updated-only", Usage: "Output a newline-seperated list of updated sources, silence other output", }, + &cli.BoolFlag{ + Name: "show-updated-only-formatted", + Usage: "Output a comma and/or ampersand list of updated sources, silence other output", + }, }, Action: func(c *cli.Context) error { - showAll := !c.Bool("show-updated-only") + showAll := !c.Bool("show-updated-only") && !c.Bool("show-updated-only-formatted") updates := []string{} if c.Args().Len() == 0 { @@ -192,10 +196,12 @@ func main() { return err } - if !showAll { + if c.Bool("show-updated-only") { for _, update := range updates { fmt.Println(update) } + } else if c.Bool("show-updated-only-formatted") { + fmt.Println(lister(updates)) } return nil @@ -320,3 +326,15 @@ func updateSource(sources *Sources, name string, source Source, show bool) (bool return updated, nil } + +func lister(items []string) string { + if len(items) == 0 { + return "" + } else if len(items) == 1 { + return items[0] + } else if len(items) == 2 { + return fmt.Sprintf("%s & %s", items[0], items[1]) + } + + return fmt.Sprintf("%s, & %s", strings.Join(items[:len(items)-1], ", "), items[len(items)-1]) +} -- cgit v1.2.3