Skip to content

Commit

Permalink
Merge pull request #44 from metafates/dev
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
metafates authored Jun 27, 2022
2 parents ec612af + ad0e4b6 commit 5deea50
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 92 deletions.
22 changes: 20 additions & 2 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The ultimate CLI manga downloader`,
Run: func(cmd *cobra.Command, args []string) {
config, _ := cmd.Flags().GetString("config")
incognito, _ := cmd.Flags().GetBool("incognito")
initConfig(config)
initConfig(config, false)

if !incognito {
initAnilist()
Expand All @@ -37,6 +37,11 @@ The ultimate CLI manga downloader`,
UserConfig.Format = FormatType(format)
}

err := ValidateConfig(UserConfig)
if err != nil {
log.Fatal(err)
}

var program *tea.Program

if UserConfig.UI.Fullscreen {
Expand Down Expand Up @@ -178,7 +183,7 @@ Useful for scripting`,

// initConfig initializes the config file
// If the given string is empty, it will use the default config file
func initConfig(config string) {
func initConfig(config string, validate bool) {
if config != "" {
// check if config is a TOML file
if filepath.Ext(config) != ".toml" {
Expand All @@ -204,6 +209,10 @@ func initConfig(config string) {
UserConfig = GetConfig("")
}

if !validate {
return
}

// check if config file is valid
err := ValidateConfig(UserConfig)

Expand Down Expand Up @@ -587,11 +596,20 @@ func init() {
inlineCmd.Flags().BoolP("open", "o", false, "open url")
inlineCmd.Flags().StringP("config", "c", "", "use config from path")
inlineCmd.Flags().SortFlags = false
_ = inlineCmd.MarkFlagRequired("query")
_ = inlineCmd.MarkFlagFilename("config", "toml")
_ = inlineCmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return Map(AvailableFormats, ToString[FormatType]), cobra.ShellCompDirectiveDefault
})
rootCmd.AddCommand(inlineCmd)

rootCmd.Flags().StringP("config", "c", "", "use config from path")
rootCmd.Flags().StringP("format", "f", "", "use custom format")
rootCmd.Flags().BoolP("incognito", "i", false, "will not sync with anilist even if enabled")
_ = rootCmd.MarkFlagFilename("config", "toml")
_ = rootCmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return Map(AvailableFormats, ToString[FormatType]), cobra.ShellCompDirectiveDefault
})

rootCmd.AddCommand(formatsCmd)
rootCmd.AddCommand(latestCmd)
Expand Down
2 changes: 1 addition & 1 deletion constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import "time"

// Version is the current version of the program.
const Version = "2.0.0"
const Version = "2.0.1"

// Mangal is a name of application
// I keep it in a constant to avoid typos
Expand Down
27 changes: 20 additions & 7 deletions cross-compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil
import subprocess

VERSION = "2.0.0"
VERSION = "2.0.1"
TAG = f"v{VERSION}"
DESCRIPTION = "The ultimate CLI manga downloader"
GITHUB = "https://github.com/metafates/mangal"
Expand Down Expand Up @@ -270,19 +270,32 @@ def generate_docker_image():
docker_image = f"""
FROM alpine:latest
ENV VERSION=v1.5.2
ENV USER=abc
ENV UID=1000
ENV GID=1000
ADD {GITHUB}/releases/download/{TAG}/{BIN}-linux-amd64 /usr/local/bin/{BIN}
RUN chmod +x /usr/local/bin/{BIN}
ENV XDG_CONFIG_HOME=/config
WORKDIR /config
VOLUME /config
ENV XDG_CONFIG_HOME=/config
RUN addgroup -g "$GID" "$USER"
RUN adduser \
--disabled-password \
--gecos "" \
--home "$(pwd)" \
--ingroup "$USER" \
--no-create-home \
--uid "$UID" \
"$USER"
ADD {GITHUB}/releases/download/{TAG}/{BIN}-linux-amd64 /usr/local/bin/{BIN}
RUN chmod +x /usr/local/bin/{BIN}
RUN /usr/local/bin/{BIN} config init
USER abc
ENTRYPOINT ["/usr/local/bin/{BIN}"]
"""
Expand Down
2 changes: 1 addition & 1 deletion downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestRemoveIfExists(t *testing.T) {
}

func TestDownloadChapter(t *testing.T) {
initConfig("")
initConfig("", false)
if testing.Short() {
t.Skip("skipping this DownloadChapter is too expensive")
}
Expand Down
51 changes: 26 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,58 @@ module github.com/metafates/mangal
go 1.18

require (
github.com/bmaupin/go-epub v1.0.0
github.com/charmbracelet/bubbles v0.10.3
github.com/charmbracelet/bubbletea v0.19.3
github.com/charmbracelet/lipgloss v0.4.0
github.com/bmaupin/go-epub v1.0.1
github.com/charmbracelet/bubbles v0.11.0
github.com/charmbracelet/bubbletea v0.21.0
github.com/charmbracelet/lipgloss v0.5.0
github.com/gocolly/colly v1.2.0
github.com/ka-weihe/fast-levenshtein v0.0.0-20201227151214-4c99ee36a1ba
github.com/pdfcpu/pdfcpu v0.3.13
github.com/pelletier/go-toml/v2 v2.0.2
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/afero v1.8.2
github.com/spf13/cobra v1.4.0
golang.org/x/exp v0.0.0-20220518171630-0b5c67f07fdf
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed
github.com/spf13/cobra v1.5.0
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467
)

require (
github.com/PuerkitoBio/goquery v1.8.0 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/antchfx/htmlquery v1.2.4 // indirect
github.com/antchfx/xmlquery v1.3.10 // indirect
github.com/antchfx/xpath v1.2.0 // indirect
github.com/antchfx/htmlquery v1.2.5 // indirect
github.com/antchfx/xmlquery v1.3.11 // indirect
github.com/antchfx/xpath v1.2.1 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/charmbracelet/harmonica v0.1.0 // indirect
github.com/containerd/console v1.0.2 // indirect
github.com/gabriel-vasile/mimetype v1.3.1 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gofrs/uuid v3.1.0+incompatible // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hhrutter/lzw v0.0.0-20190829144645-6f07a24e8650 // indirect
github.com/hhrutter/tiff v0.0.0-20190829141212-736cae8d0bc7 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kennygrant/sanitize v1.2.4 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.9.0 // indirect
github.com/muesli/termenv v0.12.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/temoto/robotstxt v1.1.2 // indirect
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50 // indirect
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8 // indirect
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
golang.org/x/text v0.3.6 // indirect
github.com/vincent-petithory/dataurl v1.0.0 // indirect
golang.org/x/image v0.0.0-20220617043117-41969df76e82 // indirect
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.25.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading

0 comments on commit 5deea50

Please sign in to comment.