From 21b4c058158f4d80a16f301ca72a91fa93951158 Mon Sep 17 00:00:00 2001 From: metafates Date: Sat, 5 Nov 2022 00:37:46 +0300 Subject: [PATCH 1/5] fix(cmd): use string slice for `--source` flag --- CHANGELOG.md | 4 ++++ cmd/root.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d95881f..b3af71c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## 4.0.2 + +- Fix invalid title in ComicInfo for chapters #130 + ## 4.0.1 This update includes just some bug-fixes and internal improvements. 🥱 diff --git a/cmd/root.go b/cmd/root.go index f3adfb03..08fa018f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -39,7 +39,7 @@ func init() { rootCmd.PersistentFlags().BoolP("write-history", "H", true, "write history of the read chapters") lo.Must0(viper.BindPFlag(constant.HistorySaveOnRead, rootCmd.PersistentFlags().Lookup("write-history"))) - rootCmd.PersistentFlags().StringArrayP("source", "S", []string{}, "default source to use") + rootCmd.PersistentFlags().StringSliceP("source", "S", []string{}, "default source to use") lo.Must0(rootCmd.RegisterFlagCompletionFunc("source", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { var sources []string From 2e0fbecb484e3f72a3364fb7a02b82d1642b4cc8 Mon Sep 17 00:00:00 2001 From: metafates Date: Wed, 9 Nov 2022 09:32:53 +0300 Subject: [PATCH 2/5] feat(inline): exact manga selector #131 --- CHANGELOG.md | 5 +++++ cmd/inline.go | 6 ++++-- constant/meta.go | 2 +- inline/inline.go | 15 +++++++++++++++ inline/options.go | 17 +++++++++++++---- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3af71c0..12846006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## 4.0.3 + +- Add `exact` manga selector for inline mode #131 +- Fix panic when manga not found in inline mode + ## 4.0.2 - Fix invalid title in ComicInfo for chapters #130 diff --git a/cmd/inline.go b/cmd/inline.go index b7173369..34da2691 100644 --- a/cmd/inline.go +++ b/cmd/inline.go @@ -107,6 +107,8 @@ When using the json flag manga selector could be omitted. That way, it will sele sources = append(sources, src) } + query := lo.Must(cmd.Flags().GetString("query")) + output := lo.Must(cmd.Flags().GetString("output")) var writer io.Writer if output != "" { @@ -119,7 +121,7 @@ When using the json flag manga selector could be omitted. That way, it will sele mangaFlag := lo.Must(cmd.Flags().GetString("manga")) mangaPicker := mo.None[inline.MangaPicker]() if mangaFlag != "" { - fn, err := inline.ParseMangaPicker(lo.Must(cmd.Flags().GetString("manga"))) + fn, err := inline.ParseMangaPicker(query, lo.Must(cmd.Flags().GetString("manga"))) handleErr(err) mangaPicker = mo.Some(fn) } @@ -136,7 +138,7 @@ When using the json flag manga selector could be omitted. That way, it will sele Sources: sources, Download: lo.Must(cmd.Flags().GetBool("download")), Json: lo.Must(cmd.Flags().GetBool("json")), - Query: lo.Must(cmd.Flags().GetString("query")), + Query: query, PopulatePages: lo.Must(cmd.Flags().GetBool("populate-pages")), IncludeAnilistManga: lo.Must(cmd.Flags().GetBool("include-anilist-manga")), MangaPicker: mangaPicker, diff --git a/constant/meta.go b/constant/meta.go index 550f9825..f2c261cb 100644 --- a/constant/meta.go +++ b/constant/meta.go @@ -2,6 +2,6 @@ package constant const ( Mangal = "mangal" - Version = "4.0.2" + Version = "4.0.3" UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" ) diff --git a/inline/inline.go b/inline/inline.go index 1301f2d1..277b403a 100644 --- a/inline/inline.go +++ b/inline/inline.go @@ -65,6 +65,21 @@ func Run(options *Options) (err error) { } manga := options.MangaPicker.MustGet()(mangas) + + if manga == nil { + if options.Json { + marshalled, err := asJson([]*source.Manga{}, options) + if err != nil { + return err + } + + _, err = options.Out.Write(marshalled) + return err + } + + return nil + } + chapters, err = manga.Source.ChaptersOf(manga) if err != nil { return err diff --git a/inline/options.go b/inline/options.go index 22214dd0..4c45d4b3 100644 --- a/inline/options.go +++ b/inline/options.go @@ -29,13 +29,14 @@ type Options struct { ChaptersFilter mo.Option[ChaptersFilter] } -func ParseMangaPicker(description string) (MangaPicker, error) { - var ( +func ParseMangaPicker(query, description string) (MangaPicker, error) { + const ( first = "first" last = "last" + exact = "exact" ) - pattern := fmt.Sprintf(`^(%s|%s|\d+)$`, first, last) + pattern := fmt.Sprintf(`^(%s|%s|%s|\d+)$`, first, last, exact) mangaPickerRegex := regexp.MustCompile(pattern) if !mangaPickerRegex.MatchString(description) { @@ -52,6 +53,14 @@ func ParseMangaPicker(description string) (MangaPicker, error) { return mangas[0] case last: return mangas[len(mangas)-1] + case exact: + for _, manga := range mangas { + if manga.Name == query { + return manga + } + } + + return nil default: index := lo.Must(strconv.ParseUint(description, 10, 16)) return mangas[util.Min(index, uint64(len(mangas)-1))] @@ -60,7 +69,7 @@ func ParseMangaPicker(description string) (MangaPicker, error) { } func ParseChaptersFilter(description string) (ChaptersFilter, error) { - var ( + const ( first = "first" last = "last" all = "all" From 086d0a8d06f08157fe4dc9e14b72099951e945e0 Mon Sep 17 00:00:00 2001 From: metafates Date: Wed, 9 Nov 2022 16:39:14 +0300 Subject: [PATCH 3/5] fix(inline): consistent output for json when no mangas found --- inline/inline.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/inline/inline.go b/inline/inline.go index 277b403a..9459b32d 100644 --- a/inline/inline.go +++ b/inline/inline.go @@ -61,6 +61,16 @@ func Run(options *Options) (err error) { var chapters []*source.Chapter if len(mangas) == 0 { + if options.Json { + marshalled, err := asJson([]*source.Manga{}, options) + if err != nil { + return err + } + + _, err = options.Out.Write(marshalled) + return err + } + return nil } From 319cc69a0525203573e1794796a690606749768f Mon Sep 17 00:00:00 2001 From: metafates Date: Wed, 9 Nov 2022 20:37:47 +0300 Subject: [PATCH 4/5] fix(inline): consistent output for json when no mangas found --- inline/inline.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inline/inline.go b/inline/inline.go index 9459b32d..44d2ff22 100644 --- a/inline/inline.go +++ b/inline/inline.go @@ -70,7 +70,7 @@ func Run(options *Options) (err error) { _, err = options.Out.Write(marshalled) return err } - + return nil } From 605eda4e77105a384717af673e828b635c1cd899 Mon Sep 17 00:00:00 2001 From: metafates Date: Wed, 9 Nov 2022 20:45:31 +0300 Subject: [PATCH 5/5] docs: update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12846006..dcb33958 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this - Add `exact` manga selector for inline mode #131 - Fix panic when manga not found in inline mode +- More consistent JSON output for inline mode ## 4.0.2