Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

v4.0.5 #141

Merged
merged 7 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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.5

- Fixes runtime crash #135
- Option to disable colors in cli help `mangal config info -k cli.colored` (why not? =P)
- Improved `config info` command output. It now shows default value and env variable name.
- Internal improvements

## 4.0.4

- Fix manga tags and genres being the same inside ComicInfo.xml #133
Expand Down
1 change: 0 additions & 1 deletion anilist/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func GetByID(id int) (*Manga, error) {
}

// SearchByName returns a list of mangas that match the given name.
// TODO: keep failed names in cache for a minute
func SearchByName(name string) ([]*Manga, error) {
name = normalizedName(name)
_ = query.Remember(name, 1)
Expand Down
1 change: 1 addition & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var configInfoCmd = &cobra.Command{

if i < len(fields)-1 {
fmt.Println()
fmt.Println()
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"fmt"
"github.com/invopop/jsonschema"
"github.com/metafates/mangal/anilist"
"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/converter"
"github.com/metafates/mangal/filesystem"
"github.com/metafates/mangal/inline"
"github.com/metafates/mangal/key"
"github.com/metafates/mangal/provider"
"github.com/metafates/mangal/query"
"github.com/metafates/mangal/source"
Expand All @@ -36,7 +36,7 @@ func init() {
inlineCmd.Flags().BoolP("populate-pages", "p", false, "Populate chapters pages")
inlineCmd.Flags().BoolP("fetch-metadata", "f", false, "Populate manga metadata")
inlineCmd.Flags().BoolP("include-anilist-manga", "a", false, "Include anilist manga in the output")
lo.Must0(viper.BindPFlag(constant.MetadataFetchAnilist, inlineCmd.Flags().Lookup("fetch-metadata")))
lo.Must0(viper.BindPFlag(key.MetadataFetchAnilist, inlineCmd.Flags().Lookup("fetch-metadata")))

inlineCmd.Flags().StringP("output", "o", "", "output file")

Expand Down Expand Up @@ -81,7 +81,7 @@ When using the json flag manga selector could be omitted. That way, it will sele
lo.Must0(cmd.MarkFlagRequired("json"))
}

if _, err := converter.Get(viper.GetString(constant.FormatsUse)); err != nil {
if _, err := converter.Get(viper.GetString(key.FormatsUse)); err != nil {
handleErr(err)
}
},
Expand All @@ -91,7 +91,7 @@ When using the json flag manga selector could be omitted. That way, it will sele
err error
)

for _, name := range viper.GetStringSlice(constant.DownloaderDefaultSources) {
for _, name := range viper.GetStringSlice(key.DownloaderDefaultSources) {
if name == "" {
handleErr(errors.New("source not set"))
}
Expand Down
26 changes: 13 additions & 13 deletions cmd/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package cmd
import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/icon"
"github.com/metafates/mangal/integration/anilist"
"github.com/metafates/mangal/key"
"github.com/metafates/mangal/log"
"github.com/metafates/mangal/open"
"github.com/samber/lo"
Expand All @@ -32,15 +32,15 @@ var integrationAnilistCmd = &cobra.Command{
See https://github.com/metafates/mangal/wiki/Anilist-Integration for more information`,
Run: func(cmd *cobra.Command, args []string) {
if lo.Must(cmd.Flags().GetBool("disable")) {
viper.Set(constant.AnilistEnable, false)
viper.Set(constant.AnilistCode, "")
viper.Set(constant.AnilistSecret, "")
viper.Set(constant.AnilistID, "")
viper.Set(key.AnilistEnable, false)
viper.Set(key.AnilistCode, "")
viper.Set(key.AnilistSecret, "")
viper.Set(key.AnilistID, "")
log.Info("Anilist integration disabled")
handleErr(viper.WriteConfig())
}

if !viper.GetBool(constant.AnilistEnable) {
if !viper.GetBool(key.AnilistEnable) {
confirm := survey.Confirm{
Message: "Anilist is disabled. Enable?",
Default: false,
Expand All @@ -53,7 +53,7 @@ See https://github.com/metafates/mangal/wiki/Anilist-Integration for more inform
return
}

viper.Set(constant.AnilistEnable, response)
viper.Set(key.AnilistEnable, response)
err = viper.WriteConfig()
if err != nil {
switch err.(type) {
Expand All @@ -67,7 +67,7 @@ See https://github.com/metafates/mangal/wiki/Anilist-Integration for more inform
}
}

if viper.GetString(constant.AnilistID) == "" {
if viper.GetString(key.AnilistID) == "" {
input := survey.Input{
Message: "Anilsit client ID is not set. Please enter it:",
Help: "",
Expand All @@ -80,12 +80,12 @@ See https://github.com/metafates/mangal/wiki/Anilist-Integration for more inform
return
}

viper.Set(constant.AnilistID, response)
viper.Set(key.AnilistID, response)
err = viper.WriteConfig()
handleErr(err)
}

if viper.GetString(constant.AnilistSecret) == "" {
if viper.GetString(key.AnilistSecret) == "" {
input := survey.Input{
Message: "Anilsit client secret is not set. Please enter it:",
Help: "",
Expand All @@ -98,12 +98,12 @@ See https://github.com/metafates/mangal/wiki/Anilist-Integration for more inform
return
}

viper.Set(constant.AnilistSecret, response)
viper.Set(key.AnilistSecret, response)
err = viper.WriteConfig()
handleErr(err)
}

if viper.GetString(constant.AnilistCode) == "" {
if viper.GetString(key.AnilistCode) == "" {
authURL := anilist.New().AuthURL()
confirmOpenInBrowser := survey.Confirm{
Message: "Open browser to authenticate with Anilist?",
Expand Down Expand Up @@ -134,7 +134,7 @@ See https://github.com/metafates/mangal/wiki/Anilist-Integration for more inform
return
}

viper.Set(constant.AnilistCode, response)
viper.Set(key.AnilistCode, response)
err = viper.WriteConfig()
handleErr(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/mini.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cmd

import (
"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/converter"
"github.com/metafates/mangal/key"
"github.com/metafates/mangal/mini"
"github.com/samber/lo"
"github.com/spf13/cobra"
Expand All @@ -24,7 +24,7 @@ var miniCmd = &cobra.Command{
Long: `Launch mangal in the mini mode.
Will try to mimic ani-cli.`,
PreRun: func(cmd *cobra.Command, args []string) {
if _, err := converter.Get(viper.GetString(constant.FormatsUse)); err != nil {
if _, err := converter.Get(viper.GetString(key.FormatsUse)); err != nil {
handleErr(err)
}
},
Expand Down
33 changes: 18 additions & 15 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/converter"
"github.com/metafates/mangal/icon"
"github.com/metafates/mangal/key"
"github.com/metafates/mangal/log"
"github.com/metafates/mangal/provider"
"github.com/metafates/mangal/style"
Expand All @@ -28,16 +29,16 @@ func init() {
lo.Must0(rootCmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return converter.Available(), cobra.ShellCompDirectiveDefault
}))
lo.Must0(viper.BindPFlag(constant.FormatsUse, rootCmd.PersistentFlags().Lookup("format")))
lo.Must0(viper.BindPFlag(key.FormatsUse, rootCmd.PersistentFlags().Lookup("format")))

rootCmd.PersistentFlags().StringP("icons", "I", "", "icons variant")
lo.Must0(rootCmd.RegisterFlagCompletionFunc("icons", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return icon.AvailableVariants(), cobra.ShellCompDirectiveDefault
}))
lo.Must0(viper.BindPFlag(constant.IconsVariant, rootCmd.PersistentFlags().Lookup("icons")))
lo.Must0(viper.BindPFlag(key.IconsVariant, rootCmd.PersistentFlags().Lookup("icons")))

rootCmd.PersistentFlags().BoolP("write-history", "H", true, "write history of the read chapters")
lo.Must0(viper.BindPFlag(constant.HistorySaveOnRead, rootCmd.PersistentFlags().Lookup("write-history")))
lo.Must0(viper.BindPFlag(key.HistorySaveOnRead, rootCmd.PersistentFlags().Lookup("write-history")))

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) {
Expand All @@ -53,7 +54,7 @@ func init() {

return sources, cobra.ShellCompDirectiveDefault
}))
lo.Must0(viper.BindPFlag(constant.DownloaderDefaultSources, rootCmd.PersistentFlags().Lookup("source")))
lo.Must0(viper.BindPFlag(key.DownloaderDefaultSources, rootCmd.PersistentFlags().Lookup("source")))

rootCmd.Flags().BoolP("continue", "c", false, "continue reading")

Expand All @@ -76,7 +77,7 @@ var rootCmd = &cobra.Command{
Long: constant.AsciiArtLogo + "\n" +
style.New().Italic(true).Foreground(color.HiRed).Render(" - The ultimate cli manga downloader"),
PreRun: func(cmd *cobra.Command, args []string) {
if _, err := converter.Get(viper.GetString(constant.FormatsUse)); err != nil {
if _, err := converter.Get(viper.GetString(key.FormatsUse)); err != nil {
handleErr(err)
}
},
Expand All @@ -95,16 +96,18 @@ var rootCmd = &cobra.Command{

// Execute adds all child commands to the root command and sets flags appropriately.
func Execute() {
// colored cobra injection
cc.Init(&cc.Config{
RootCmd: rootCmd,
Headings: cc.HiCyan + cc.Bold + cc.Underline,
Commands: cc.HiYellow + cc.Bold,
Example: cc.Italic,
ExecName: cc.Bold,
Flags: cc.Bold,
FlagsDataType: cc.Italic + cc.HiBlue,
})
if viper.GetBool(key.CliColored) {
// colored cobra injection
cc.Init(&cc.Config{
RootCmd: rootCmd,
Headings: cc.HiCyan + cc.Bold + cc.Underline,
Commands: cc.HiYellow + cc.Bold,
Example: cc.Italic,
ExecName: cc.Bold,
Flags: cc.Bold,
FlagsDataType: cc.Italic + cc.HiBlue,
})
}

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/metafates/mangal/color"
"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/key"
"github.com/metafates/mangal/tui"
"github.com/metafates/mangal/util"
"github.com/spf13/viper"
Expand Down Expand Up @@ -147,7 +148,7 @@ var sourcesGenCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cmd.SetOut(os.Stdout)

author := viper.GetString(constant.GenAuthor)
author := viper.GetString(key.GenAuthor)
if author == "" {
usr, err := user.Current()
if err == nil {
Expand Down
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/filesystem"
"github.com/metafates/mangal/key"
"github.com/metafates/mangal/where"
"github.com/samber/lo"
"github.com/spf13/viper"
Expand Down Expand Up @@ -74,7 +75,7 @@ func setDefaults() {
// resolveAliases resolves the aliases for the paths
func resolveAliases() {
home := lo.Must(os.UserHomeDir())
path := viper.GetString(constant.DownloaderPath)
path := viper.GetString(key.DownloaderPath)

if path == "~" {
path = home
Expand All @@ -84,5 +85,5 @@ func resolveAliases() {

path = os.ExpandEnv(path)

viper.Set(constant.DownloaderPath, path)
viper.Set(key.DownloaderPath, path)
}
Loading