Skip to content

Commit

Permalink
fix: rename const folder, change search args and others
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsm-dev committed Sep 23, 2022
1 parent ea19f4d commit 63d4b42
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 44 deletions.
4 changes: 2 additions & 2 deletions commands/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"io"

"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
log "github.com/ci-monk/loli/internal/log"
"github.com/ci-monk/loli/internal/utils"
)
Expand All @@ -19,7 +19,7 @@ var (
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by loli main(). It only needs to happen once to the rootCmd.
func Execute() {
outputRender, err := utils.RenderMarkdown(constants.Welcome)
outputRender, err := utils.RenderMarkdown(consts.Welcome)
if err != nil {
log.Fatal("Render glamour markdown")
}
Expand Down
4 changes: 2 additions & 2 deletions commands/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
"github.com/spf13/cobra"
)

Expand All @@ -13,7 +13,7 @@ var excludeDesc = false
var completionCmd = &cobra.Command{
Use: "completion <shell>",
Short: "Generate shell completion scripts",
Long: constants.CompletionHelpMessage,
Long: consts.CompletionHelpMessage,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: func(cmd *cobra.Command, args []string) error {
if cobra.ExactArgs(1)(cmd, args) != nil || cobra.OnlyValidArgs(cmd, args) != nil {
Expand Down
6 changes: 3 additions & 3 deletions commands/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commands

import (
"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
"github.com/ci-monk/loli/internal/debug"
log "github.com/ci-monk/loli/internal/log"
"github.com/ci-monk/loli/internal/utils"
Expand All @@ -11,7 +11,7 @@ import (
var config = log.Config{}

var rootCmd = &cobra.Command{
Use: constants.BinaryName,
Use: consts.BinaryName,
Short: "Find the anime scene by image using your terminal",
Long: `Description:
Expand All @@ -33,7 +33,7 @@ var rootCmd = &cobra.Command{
}

if timeout, _ := cmd.Flags().GetInt("timeout"); timeout > 0 {
constants.TimeoutInSeconds = timeout
consts.TimeoutInSeconds = timeout
}
},
}
Expand Down
7 changes: 2 additions & 5 deletions commands/search_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ import (
"github.com/spf13/cobra"
)

var animeFile string

var searchFileCmd = &cobra.Command{
Use: "file",
Args: cobra.MinimumNArgs(1),
Short: "Search for the anime scene by existing image file",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
trace.SearchAnimeByFile(animeFile, searchPretty)
trace.SearchAnimeByFile(args[0], searchPretty)
},
}

func init() {
searchFileCmd.PersistentFlags().StringVarP(&animeFile, "file", "f", animeFile, "An anime image file")
searchFileCmd.MarkFlagRequired("file")
searchCmd.AddCommand(searchFileCmd)
}
7 changes: 2 additions & 5 deletions commands/search_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ import (
"github.com/spf13/cobra"
)

var animeLink string

var searchLinkCmd = &cobra.Command{
Use: "link",
Args: cobra.MinimumNArgs(1),
Short: "Search for the anime scene by existing image link",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
trace.SearchAnimeByLink(animeLink, searchPretty)
trace.SearchAnimeByLink(args[0], searchPretty)
},
}

func init() {
searchLinkCmd.PersistentFlags().StringVarP(&animeLink, "url", "u", animeLink, "An anime image url")
searchLinkCmd.MarkFlagRequired("link")
searchCmd.AddCommand(searchLinkCmd)
}
8 changes: 4 additions & 4 deletions internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"net/http"
"time"

"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
"github.com/ci-monk/loli/internal/debug"
)

var (
// HTTPClient variable - is the client used to make HTTP calls in loli cli.
// For more information: https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779
HTTPClient = &http.Client{
Timeout: time.Duration(constants.TimeoutInSeconds) * time.Second,
Timeout: time.Duration(consts.TimeoutInSeconds) * time.Second,
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Expand All @@ -29,7 +29,7 @@ var (
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: constants.InsecureSkipVerify,
InsecureSkipVerify: consts.InsecureSkipVerify,
},
},
}
Expand All @@ -54,7 +54,7 @@ func (c *Client) NewRequest(method, url string, body io.Reader) (*http.Request,
return nil, error
}

req.Header.Set("User-Agent", constants.UserAgent)
req.Header.Set("User-Agent", consts.UserAgent)

if c.ContentType == "" {
req.Header.Set("Content-Type", "application/json")
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"io/ioutil"
"net/http"

"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
"github.com/ci-monk/loli/internal/log"
)

func (a *Asset) download() (*bytes.Reader, error) {
downloadReleaseURL := fmt.Sprintf("%s/assets/%d", constants.ReleaseURL, a.ID)
downloadReleaseURL := fmt.Sprintf("%s/assets/%d", consts.ReleaseURL, a.ID)
log.Debug(downloadReleaseURL)

request, err := http.NewRequest("GET", downloadReleaseURL, nil)
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/blang/semver"
"github.com/ci-monk/loli/internal/api"
"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
"github.com/ci-monk/loli/internal/log"
update "github.com/inconshreveable/go-update"
)
Expand Down Expand Up @@ -133,7 +133,7 @@ func (c *CLI) Upgrade() error {
func (c *CLI) fetchLatestRelease() error {
log.Debug("Fetch latest release")

latestReleaseURL := fmt.Sprintf("%s/%s", constants.ReleaseURL, "latest")
latestReleaseURL := fmt.Sprintf("%s/%s", consts.ReleaseURL, "latest")
resp, err := api.HTTPClient.Get(latestReleaseURL)
if err != nil {
return err
Expand Down Expand Up @@ -193,7 +193,7 @@ func extractBinary(source *bytes.Reader, os string) (binary io.ReadCloser, err e
return nil, err
}

tmpfile, err := ioutil.TempFile("", fmt.Sprintf("temp-%s", constants.ProjectURL))
tmpfile, err := ioutil.TempFile("", fmt.Sprintf("temp-%s", consts.ProjectURL))
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package constants
package consts

const (
// DefaultTimestampFormat default time format.
Expand Down
8 changes: 4 additions & 4 deletions internal/log/logger_formatters.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package log

import (
"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
"github.com/sirupsen/logrus"
)

Expand All @@ -12,7 +12,7 @@ func textFormatter() *logrus.TextFormatter {
ForceColors: true,
EnvironmentOverrideColors: true,
FullTimestamp: true,
TimestampFormat: constants.DefaultTimestampFormat,
TimestampFormat: consts.DefaultTimestampFormat,
DisableLevelTruncation: true,
}
}
Expand All @@ -24,15 +24,15 @@ func colorFormatter() *logrus.TextFormatter {
ForceColors: true,
EnvironmentOverrideColors: true,
FullTimestamp: true,
TimestampFormat: constants.DefaultTimestampFormat,
TimestampFormat: consts.DefaultTimestampFormat,
DisableLevelTruncation: true,
}
}

// Configure the logrus format to use "json" formatter
func jsonFormatter(pretty bool) *logrus.JSONFormatter {
return &logrus.JSONFormatter{
TimestampFormat: constants.DefaultTimestampFormat,
TimestampFormat: consts.DefaultTimestampFormat,
DisableTimestamp: false,
PrettyPrint: pretty,
}
Expand Down
4 changes: 2 additions & 2 deletions internal/trace/search_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

"github.com/briandowns/spinner"
"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
log "github.com/ci-monk/loli/internal/log"
"github.com/ci-monk/loli/internal/types"
"github.com/ci-monk/loli/internal/utils"
Expand All @@ -25,7 +25,7 @@ import (

// SearchAnimeByFile function
func SearchAnimeByFile(animeFile string, pretty bool) {
searchURL := constants.TraceMoeSearchAnimeByFile
searchURL := consts.TraceMoeSearchAnimeByFile
log.Infoln(searchURL)

termenv.HideCursor()
Expand Down
4 changes: 2 additions & 2 deletions internal/trace/search_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

"github.com/briandowns/spinner"
"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
log "github.com/ci-monk/loli/internal/log"
"github.com/ci-monk/loli/internal/types"
"github.com/ci-monk/loli/internal/utils"
Expand All @@ -23,7 +23,7 @@ import (

// SearchAnimeByLink function
func SearchAnimeByLink(animeLink string, pretty bool) {
searchURL := constants.TraceMoeSearchAnimeByLink
searchURL := consts.TraceMoeSearchAnimeByLink
log.Info(searchURL)

fullURL := searchURL + animeLink
Expand Down
4 changes: 2 additions & 2 deletions internal/trace/search_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"
"strconv"

"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
log "github.com/ci-monk/loli/internal/log"
"github.com/ci-monk/loli/internal/types"
"github.com/fatih/color"
Expand All @@ -17,7 +17,7 @@ import (

// SearchUsage function
func SearchUsage(pretty bool) {
searchURL := constants.TraceMoeUsage
searchURL := consts.TraceMoeUsage
log.Infoln(searchURL)

resp, error := http.Get(searchURL)
Expand Down
4 changes: 2 additions & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/charmbracelet/glamour"
"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
"github.com/fatih/color"
"github.com/kyokomi/emoji/v2"
au "github.com/logrusorgru/aurora"
Expand Down Expand Up @@ -88,7 +88,7 @@ func CreateLogFile(logdir, logfile string) string {
".pid"+
pid+
"."+
time.Now().Format(constants.DefaultTimestampFormat)+
time.Now().Format(consts.DefaultTimestampFormat)+
".log",
)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package version
import (
"os"

"github.com/ci-monk/loli/internal/constants"
"github.com/ci-monk/loli/internal/consts"
"github.com/jedib0t/go-pretty/table"
"github.com/pterm/pterm"
)

// Default build-time variable. These variables are populated via the Go ldflags. This will be filled in by the compiler
var (
cliName = constants.BinaryName // default name for this CLI
cliName = consts.BinaryName // default name for this CLI
cliVersion = "0.0.0" // value from VERSION file
builtDate = "1970-01-01T00:00:00Z" // output from `date -u +'%Y-%m-%dT%H:%M:%SZ'`
builtBy = "unknown-built-by" // built agent (GoRelease, Makefile...)
commit = "unknown-commit" // output from `git rev-parse HEAD`
commitShort = "unknown-short-commit" // output from `git rev-parse --short HEAD`
commitBranch = "unknown-commit-branch" // output from `git rev-parse --abbrev-ref HEAD`
projectURL = constants.ProjectURL // github project url
projectURL = consts.ProjectURL // github project url
goVersion = "unknown-go-version" // output from `go version`
)

Expand All @@ -32,7 +32,7 @@ func GetShortDetails() {
pterm.DefaultHeader.
WithMargin(5).
WithBackgroundStyle(pterm.NewStyle(pterm.BgBlack)).
Printf("✨ %s version details ✨", constants.BinaryName)
Printf("✨ %s version details ✨", consts.BinaryName)
pterm.Println()
versionTable := table.NewWriter()
versionTable.SetOutputMirror(os.Stdout)
Expand All @@ -56,7 +56,7 @@ func GetPrettyDetails() {
pterm.DefaultHeader.
WithMargin(5).
WithBackgroundStyle(pterm.NewStyle(pterm.BgBlack)).
Printf("✨ %s version details ✨", constants.BinaryName)
Printf("✨ %s version details ✨", consts.BinaryName)
pterm.Println()
versionTable := table.NewWriter()
versionTable.SetOutputMirror(os.Stdout)
Expand Down

0 comments on commit 63d4b42

Please sign in to comment.