mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 21:16:30 +02:00
Linter fixes (error handling, unused constants, raw strings)
This commit is contained in:
parent
da04eb7f13
commit
aeae76a569
@ -56,6 +56,10 @@ func init() {
|
|||||||
_ = viper.BindPFlag("meta-folder-base", rootCmd.PersistentFlags().Lookup("meta-folder-base"))
|
_ = viper.BindPFlag("meta-folder-base", rootCmd.PersistentFlags().Lookup("meta-folder-base"))
|
||||||
|
|
||||||
defaultCacheDir, err := core.GetPackwizCache()
|
defaultCacheDir, err := core.GetPackwizCache()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
rootCmd.PersistentFlags().String("cache", defaultCacheDir, "The directory where packwiz will cache downloaded mods")
|
rootCmd.PersistentFlags().String("cache", defaultCacheDir, "The directory where packwiz will cache downloaded mods")
|
||||||
_ = viper.BindPFlag("cache.directory", rootCmd.PersistentFlags().Lookup("cache"))
|
_ = viper.BindPFlag("cache.directory", rootCmd.PersistentFlags().Lookup("cache"))
|
||||||
|
|
||||||
|
@ -58,7 +58,10 @@ var serveCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
indexPageBuf := new(bytes.Buffer)
|
indexPageBuf := new(bytes.Buffer)
|
||||||
t.Execute(indexPageBuf, struct{ Port string }{Port: port})
|
err = t.Execute(indexPageBuf, struct{ Port string }{Port: port})
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to compile index page template: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
// Force-disable no-internal-hashes mode (equiv to --build flag in refresh) for serving over HTTP
|
// Force-disable no-internal-hashes mode (equiv to --build flag in refresh) for serving over HTTP
|
||||||
if viper.GetBool("no-internal-hashes") {
|
if viper.GetBool("no-internal-hashes") {
|
||||||
|
@ -595,7 +595,7 @@ func CreateDownloadSession(mods []*Mod, hashesToObtain []string) (DownloadSessio
|
|||||||
|
|
||||||
// Get necessary metadata for all files
|
// Get necessary metadata for all files
|
||||||
for _, mod := range mods {
|
for _, mod := range mods {
|
||||||
if mod.Download.Mode == "url" || mod.Download.Mode == "" {
|
if mod.Download.Mode == ModeURL || mod.Download.Mode == "" {
|
||||||
downloadSession.downloadTasks = append(downloadSession.downloadTasks, downloadTask{
|
downloadSession.downloadTasks = append(downloadSession.downloadTasks, downloadTask{
|
||||||
mod: mod,
|
mod: mod,
|
||||||
url: mod.Download.URL,
|
url: mod.Download.URL,
|
||||||
|
@ -208,9 +208,8 @@ func (in *Index) Refresh() error {
|
|||||||
pathIndex, _ := filepath.Abs(in.indexFile)
|
pathIndex, _ := filepath.Abs(in.indexFile)
|
||||||
|
|
||||||
packRoot := in.GetPackRoot()
|
packRoot := in.GetPackRoot()
|
||||||
ignoreExists := true
|
|
||||||
pathIgnore, _ := filepath.Abs(filepath.Join(packRoot, ".packwizignore"))
|
pathIgnore, _ := filepath.Abs(filepath.Join(packRoot, ".packwizignore"))
|
||||||
ignore, ignoreExists := readGitignore(filepath.Join(packRoot, ".packwizignore"))
|
ignore, ignoreExists := readGitignore(pathIgnore)
|
||||||
|
|
||||||
var fileList []string
|
var fileList []string
|
||||||
err := filepath.Walk(packRoot, func(path string, info os.FileInfo, err error) error {
|
err := filepath.Walk(packRoot, func(path string, info os.FileInfo, err error) error {
|
||||||
|
14
core/mod.go
14
core/mod.go
@ -25,8 +25,8 @@ type Mod struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
modeURL string = "url"
|
ModeURL string = "url"
|
||||||
modeCF string = "metadata:curseforge"
|
ModeCF string = "metadata:curseforge"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ModDownload specifies how to download the mod file
|
// ModDownload specifies how to download the mod file
|
||||||
@ -132,11 +132,11 @@ func (m Mod) GetDestFilePath() string {
|
|||||||
return filepath.Join(filepath.Dir(m.metaFile), filepath.FromSlash(m.FileName))
|
return filepath.Join(filepath.Dir(m.metaFile), filepath.FromSlash(m.FileName))
|
||||||
}
|
}
|
||||||
|
|
||||||
var slugifyRegex1 = regexp.MustCompile("\\(.*\\)")
|
var slugifyRegex1 = regexp.MustCompile(`\(.*\)`)
|
||||||
var slugifyRegex2 = regexp.MustCompile(" - .+")
|
var slugifyRegex2 = regexp.MustCompile(` - .+`)
|
||||||
var slugifyRegex3 = regexp.MustCompile("[^a-z\\d]")
|
var slugifyRegex3 = regexp.MustCompile(`[^a-z\d]`)
|
||||||
var slugifyRegex4 = regexp.MustCompile("-+")
|
var slugifyRegex4 = regexp.MustCompile(`-+`)
|
||||||
var slugifyRegex5 = regexp.MustCompile("^-|-$")
|
var slugifyRegex5 = regexp.MustCompile(`^-|-$`)
|
||||||
|
|
||||||
func SlugifyName(name string) string {
|
func SlugifyName(name string) string {
|
||||||
lower := strings.ToLower(name)
|
lower := strings.ToLower(name)
|
||||||
|
@ -29,7 +29,7 @@ func init() {
|
|||||||
core.MetaDownloaders["curseforge"] = cfDownloader{}
|
core.MetaDownloaders["curseforge"] = cfDownloader{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var snapshotVersionRegex = regexp.MustCompile("(?:Snapshot )?(\\d+)w0?(0|[1-9]\\d*)([a-z])")
|
var snapshotVersionRegex = regexp.MustCompile(`(?:Snapshot )?(\d+)w0?(0|[1-9]\d*)([a-z])`)
|
||||||
|
|
||||||
var snapshotNames = [...]string{"-pre", " Pre-Release ", " Pre-release ", "-rc"}
|
var snapshotNames = [...]string{"-pre", " Pre-Release ", " Pre-release ", "-rc"}
|
||||||
|
|
||||||
@ -119,9 +119,9 @@ func getCurseforgeVersions(mcVersions []string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var urlRegexes = [...]*regexp.Regexp{
|
var urlRegexes = [...]*regexp.Regexp{
|
||||||
regexp.MustCompile("^https?://(?P<game>minecraft)\\.curseforge\\.com/projects/(?P<slug>[^/]+)(?:/(?:files|download)/(?P<fileID>\\d+))?"),
|
regexp.MustCompile(`^https?://(?P<game>minecraft)\.curseforge\.com/projects/(?P<slug>[^/]+)(?:/(?:files|download)/(?P<fileID>\d+))?`),
|
||||||
regexp.MustCompile("^https?://(?:www\\.|beta\\.)?curseforge\\.com/(?P<game>[^/]+)/(?P<category>[^/]+)/(?P<slug>[^/]+)(?:/(?:files|download)/(?P<fileID>\\d+))?"),
|
regexp.MustCompile(`^https?://(?:www\.|beta\.)?curseforge\.com/(?P<game>[^/]+)/(?P<category>[^/]+)/(?P<slug>[^/]+)(?:/(?:files|download)/(?P<fileID>\d+))?`),
|
||||||
regexp.MustCompile("^(?P<slug>[a-z][\\da-z\\-_]{0,127})$"),
|
regexp.MustCompile(`^(?P<slug>[a-z][\da-z\-_]{0,127})$`),
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseSlugOrUrl(url string) (game string, category string, slug string, fileID uint32, err error) {
|
func parseSlugOrUrl(url string) (game string, category string, slug string, fileID uint32, err error) {
|
||||||
@ -203,7 +203,7 @@ func createModFile(modInfo modInfo, fileInfo modFileInfo, index *core.Index, opt
|
|||||||
Download: core.ModDownload{
|
Download: core.ModDownload{
|
||||||
HashFormat: hashFormat,
|
HashFormat: hashFormat,
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
Mode: "metadata:curseforge",
|
Mode: core.ModeCF,
|
||||||
},
|
},
|
||||||
Option: optional,
|
Option: optional,
|
||||||
Update: updateMap,
|
Update: updateMap,
|
||||||
@ -456,7 +456,7 @@ func (u cfUpdater) DoUpdate(mods []*core.Mod, cachedState []interface{}) error {
|
|||||||
v.Download = core.ModDownload{
|
v.Download = core.ModDownload{
|
||||||
HashFormat: hashFormat,
|
HashFormat: hashFormat,
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
Mode: "metadata:curseforge",
|
Mode: core.ModeCF,
|
||||||
}
|
}
|
||||||
|
|
||||||
v.Update["curseforge"]["project-id"] = modState.ID
|
v.Update["curseforge"]["project-id"] = modState.ID
|
||||||
|
@ -280,7 +280,7 @@ var whitelistedHosts = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func canBeIncludedDirectly(mod *core.Mod, restrictDomains bool) bool {
|
func canBeIncludedDirectly(mod *core.Mod, restrictDomains bool) bool {
|
||||||
if mod.Download.Mode == "url" || mod.Download.Mode == "" {
|
if mod.Download.Mode == core.ModeURL || mod.Download.Mode == "" {
|
||||||
if !restrictDomains {
|
if !restrictDomains {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,9 @@ func getLatestVersion(projectID string, name string, pack core.Pack) (*modrinthA
|
|||||||
GameVersions: gameVersions,
|
GameVersions: gameVersions,
|
||||||
Loaders: loaders,
|
Loaders: loaders,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to fetch latest version: %w", err)
|
||||||
|
}
|
||||||
if len(result) == 0 {
|
if len(result) == 0 {
|
||||||
// TODO: retry with datapack specified, to determine what the issue is? or just request all and filter afterwards
|
// TODO: retry with datapack specified, to determine what the issue is? or just request all and filter afterwards
|
||||||
return nil, errors.New("no valid versions found\nUse the acceptable-game-versions option to accept more game versions\nTo use datapacks, add a datapack loader mod and specify the datapack-folder option with the folder this mod loads datapacks from")
|
return nil, errors.New("no valid versions found\nUse the acceptable-game-versions option to accept more game versions\nTo use datapacks, add a datapack loader mod and specify the datapack-folder option with the folder this mod loads datapacks from")
|
||||||
|
@ -126,6 +126,9 @@ var installCmd = &cobra.Command{
|
|||||||
func getSha1(url string) (string, error) {
|
func getSha1(url string) (string, error) {
|
||||||
// TODO: hook up to existing cache system? might not be that useful
|
// TODO: hook up to existing cache system? might not be that useful
|
||||||
mainHasher, err := core.GetHashImpl("sha1")
|
mainHasher, err := core.GetHashImpl("sha1")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user