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

Commit 0735aa2

Browse files
authored
Merge pull request #141 from metafates/dev
2 parents 6dea3e2 + 8b24519 commit 0735aa2

File tree

169 files changed

+3791
-2102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+3791
-2102
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to
66
[Semantic Versioning](https://semver.org).
77

8+
## 4.0.5
9+
10+
- Fixes runtime crash #135
11+
- Option to disable colors in cli help `mangal config info -k cli.colored` (why not? =P)
12+
- Improved `config info` command output. It now shows default value and env variable name.
13+
- Internal improvements
14+
815
## 4.0.4
916

1017
- Fix manga tags and genres being the same inside ComicInfo.xml #133

anilist/search.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ func GetByID(id int) (*Manga, error) {
8686
}
8787

8888
// SearchByName returns a list of mangas that match the given name.
89-
// TODO: keep failed names in cache for a minute
9089
func SearchByName(name string) ([]*Manga, error) {
9190
name = normalizedName(name)
9291
_ = query.Remember(name, 1)

cmd/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ var configInfoCmd = &cobra.Command{
9494

9595
if i < len(fields)-1 {
9696
fmt.Println()
97+
fmt.Println()
9798
}
9899
}
99100
},

cmd/inline.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"fmt"
77
"github.com/invopop/jsonschema"
88
"github.com/metafates/mangal/anilist"
9-
"github.com/metafates/mangal/constant"
109
"github.com/metafates/mangal/converter"
1110
"github.com/metafates/mangal/filesystem"
1211
"github.com/metafates/mangal/inline"
12+
"github.com/metafates/mangal/key"
1313
"github.com/metafates/mangal/provider"
1414
"github.com/metafates/mangal/query"
1515
"github.com/metafates/mangal/source"
@@ -36,7 +36,7 @@ func init() {
3636
inlineCmd.Flags().BoolP("populate-pages", "p", false, "Populate chapters pages")
3737
inlineCmd.Flags().BoolP("fetch-metadata", "f", false, "Populate manga metadata")
3838
inlineCmd.Flags().BoolP("include-anilist-manga", "a", false, "Include anilist manga in the output")
39-
lo.Must0(viper.BindPFlag(constant.MetadataFetchAnilist, inlineCmd.Flags().Lookup("fetch-metadata")))
39+
lo.Must0(viper.BindPFlag(key.MetadataFetchAnilist, inlineCmd.Flags().Lookup("fetch-metadata")))
4040

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

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

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

94-
for _, name := range viper.GetStringSlice(constant.DownloaderDefaultSources) {
94+
for _, name := range viper.GetStringSlice(key.DownloaderDefaultSources) {
9595
if name == "" {
9696
handleErr(errors.New("source not set"))
9797
}

cmd/integration.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package cmd
33
import (
44
"fmt"
55
"github.com/AlecAivazis/survey/v2"
6-
"github.com/metafates/mangal/constant"
76
"github.com/metafates/mangal/icon"
87
"github.com/metafates/mangal/integration/anilist"
8+
"github.com/metafates/mangal/key"
99
"github.com/metafates/mangal/log"
1010
"github.com/metafates/mangal/open"
1111
"github.com/samber/lo"
@@ -32,15 +32,15 @@ var integrationAnilistCmd = &cobra.Command{
3232
See https://github.com/metafates/mangal/wiki/Anilist-Integration for more information`,
3333
Run: func(cmd *cobra.Command, args []string) {
3434
if lo.Must(cmd.Flags().GetBool("disable")) {
35-
viper.Set(constant.AnilistEnable, false)
36-
viper.Set(constant.AnilistCode, "")
37-
viper.Set(constant.AnilistSecret, "")
38-
viper.Set(constant.AnilistID, "")
35+
viper.Set(key.AnilistEnable, false)
36+
viper.Set(key.AnilistCode, "")
37+
viper.Set(key.AnilistSecret, "")
38+
viper.Set(key.AnilistID, "")
3939
log.Info("Anilist integration disabled")
4040
handleErr(viper.WriteConfig())
4141
}
4242

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

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

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

83-
viper.Set(constant.AnilistID, response)
83+
viper.Set(key.AnilistID, response)
8484
err = viper.WriteConfig()
8585
handleErr(err)
8686
}
8787

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

101-
viper.Set(constant.AnilistSecret, response)
101+
viper.Set(key.AnilistSecret, response)
102102
err = viper.WriteConfig()
103103
handleErr(err)
104104
}
105105

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

137-
viper.Set(constant.AnilistCode, response)
137+
viper.Set(key.AnilistCode, response)
138138
err = viper.WriteConfig()
139139
handleErr(err)
140140
}

cmd/mini.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package cmd
22

33
import (
4-
"github.com/metafates/mangal/constant"
54
"github.com/metafates/mangal/converter"
5+
"github.com/metafates/mangal/key"
66
"github.com/metafates/mangal/mini"
77
"github.com/samber/lo"
88
"github.com/spf13/cobra"
@@ -24,7 +24,7 @@ var miniCmd = &cobra.Command{
2424
Long: `Launch mangal in the mini mode.
2525
Will try to mimic ani-cli.`,
2626
PreRun: func(cmd *cobra.Command, args []string) {
27-
if _, err := converter.Get(viper.GetString(constant.FormatsUse)); err != nil {
27+
if _, err := converter.Get(viper.GetString(key.FormatsUse)); err != nil {
2828
handleErr(err)
2929
}
3030
},

cmd/root.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/metafates/mangal/constant"
88
"github.com/metafates/mangal/converter"
99
"github.com/metafates/mangal/icon"
10+
"github.com/metafates/mangal/key"
1011
"github.com/metafates/mangal/log"
1112
"github.com/metafates/mangal/provider"
1213
"github.com/metafates/mangal/style"
@@ -28,16 +29,16 @@ func init() {
2829
lo.Must0(rootCmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
2930
return converter.Available(), cobra.ShellCompDirectiveDefault
3031
}))
31-
lo.Must0(viper.BindPFlag(constant.FormatsUse, rootCmd.PersistentFlags().Lookup("format")))
32+
lo.Must0(viper.BindPFlag(key.FormatsUse, rootCmd.PersistentFlags().Lookup("format")))
3233

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

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

4243
rootCmd.PersistentFlags().StringSliceP("source", "S", []string{}, "default source to use")
4344
lo.Must0(rootCmd.RegisterFlagCompletionFunc("source", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
@@ -53,7 +54,7 @@ func init() {
5354

5455
return sources, cobra.ShellCompDirectiveDefault
5556
}))
56-
lo.Must0(viper.BindPFlag(constant.DownloaderDefaultSources, rootCmd.PersistentFlags().Lookup("source")))
57+
lo.Must0(viper.BindPFlag(key.DownloaderDefaultSources, rootCmd.PersistentFlags().Lookup("source")))
5758

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

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

9697
// Execute adds all child commands to the root command and sets flags appropriately.
9798
func Execute() {
98-
// colored cobra injection
99-
cc.Init(&cc.Config{
100-
RootCmd: rootCmd,
101-
Headings: cc.HiCyan + cc.Bold + cc.Underline,
102-
Commands: cc.HiYellow + cc.Bold,
103-
Example: cc.Italic,
104-
ExecName: cc.Bold,
105-
Flags: cc.Bold,
106-
FlagsDataType: cc.Italic + cc.HiBlue,
107-
})
99+
if viper.GetBool(key.CliColored) {
100+
// colored cobra injection
101+
cc.Init(&cc.Config{
102+
RootCmd: rootCmd,
103+
Headings: cc.HiCyan + cc.Bold + cc.Underline,
104+
Commands: cc.HiYellow + cc.Bold,
105+
Example: cc.Italic,
106+
ExecName: cc.Bold,
107+
Flags: cc.Bold,
108+
FlagsDataType: cc.Italic + cc.HiBlue,
109+
})
110+
}
108111

109112
if err := rootCmd.Execute(); err != nil {
110113
fmt.Println(err)

cmd/sources.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/metafates/mangal/color"
66
"github.com/metafates/mangal/constant"
7+
"github.com/metafates/mangal/key"
78
"github.com/metafates/mangal/tui"
89
"github.com/metafates/mangal/util"
910
"github.com/spf13/viper"
@@ -147,7 +148,7 @@ var sourcesGenCmd = &cobra.Command{
147148
Run: func(cmd *cobra.Command, args []string) {
148149
cmd.SetOut(os.Stdout)
149150

150-
author := viper.GetString(constant.GenAuthor)
151+
author := viper.GetString(key.GenAuthor)
151152
if author == "" {
152153
usr, err := user.Current()
153154
if err == nil {

config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/metafates/mangal/constant"
66
"github.com/metafates/mangal/filesystem"
7+
"github.com/metafates/mangal/key"
78
"github.com/metafates/mangal/where"
89
"github.com/samber/lo"
910
"github.com/spf13/viper"
@@ -74,7 +75,7 @@ func setDefaults() {
7475
// resolveAliases resolves the aliases for the paths
7576
func resolveAliases() {
7677
home := lo.Must(os.UserHomeDir())
77-
path := viper.GetString(constant.DownloaderPath)
78+
path := viper.GetString(key.DownloaderPath)
7879

7980
if path == "~" {
8081
path = home
@@ -84,5 +85,5 @@ func resolveAliases() {
8485

8586
path = os.ExpandEnv(path)
8687

87-
viper.Set(constant.DownloaderPath, path)
88+
viper.Set(key.DownloaderPath, path)
8889
}

0 commit comments

Comments
 (0)