Skip to content

Commit

Permalink
Merge pull request #132 from metafates/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
metafates authored Nov 9, 2022
2 parents db59ec9 + 605eda4 commit ad9d75b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ 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
- More consistent JSON output for inline mode

## 4.0.2

- Fix invalid title in ComicInfo for chapters #130

## 4.0.1

This update includes just some bug-fixes and internal improvements. 🥱
Expand Down
6 changes: 4 additions & 2 deletions cmd/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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)
}
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion constant/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
25 changes: 25 additions & 0 deletions inline/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,35 @@ 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
}

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
Expand Down
17 changes: 13 additions & 4 deletions inline/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))]
Expand All @@ -60,7 +69,7 @@ func ParseMangaPicker(description string) (MangaPicker, error) {
}

func ParseChaptersFilter(description string) (ChaptersFilter, error) {
var (
const (
first = "first"
last = "last"
all = "all"
Expand Down

0 comments on commit ad9d75b

Please sign in to comment.