cmd

package
v0.0.0-...-3b04d4b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 26 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	OnlyMain         = "main"
	OnlyDependencies = "dependencies"
)

What --only takes: the mods that were added on their own, or those that were added because another needs them

Variables

View Source
var MarkDependencyCmd = &cobra.Command{
	Use:   "mark-dependency",
	Short: "Mark a mod as having been added as a dependency of another mod, rather than a main mod",
	Long:  "Mark a mod as having been added as a dependency of another mod, rather than a main mod.\n\n" + modRefHelp,
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		markModAsDependency(args, true)
	},
}

MarkDependencyCmd represents the mark-dependency command

View Source
var PinCmd = &cobra.Command{
	Use:     "pin",
	Short:   "Pin a file so it does not get updated automatically",
	Long:    "Pin a file so it does not get updated automatically.\n\n" + modRefHelp,
	Aliases: []string{"hold"},
	Args:    cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		pinMod(args, true)
	},
}

PinCmd represents the pin command

View Source
var UnmarkDependencyCmd = &cobra.Command{
	Use:   "unmark-dependency",
	Short: "Mark a mod as a main mod, rather than a dependency of another mod",
	Long:  "Mark a mod as a main mod, rather than a dependency of another mod.\n\n" + modRefHelp,
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		markModAsDependency(args, false)
	},
}

UnmarkDependencyCmd represents the unmark-dependency command

View Source
var UnpinCmd = &cobra.Command{
	Use:     "unpin",
	Short:   "Unpin a file so it receives updates",
	Long:    "Unpin a file so it receives updates.\n\n" + modRefHelp,
	Aliases: []string{"unhold"},
	Args:    cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		pinMod(args, false)
	},
}

UnpinCmd represents the unpin command

View Source
var UpdateCmd = &cobra.Command{
	Use:     "update [name]",
	Short:   "Update an external file (or all external files) in the modpack",
	Long:    "Update an external file, or all of them with --all.\n\n" + modRefHelp,
	Aliases: []string{"upgrade"},
	Args:    cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		ui.Muted.Println("Loading modpack...")
		pack, err := core.LoadPack()
		if err != nil {
			ui.Error.Println(err)
			os.Exit(1)
		}
		index, err := pack.LoadIndex()
		if err != nil {
			ui.Error.Println(err)
			os.Exit(1)
		}

		var singleUpdatedName string
		if viper.GetBool("update.all") {
			ui.Muted.Println("Reading metadata files...")
			mods, err := index.LoadAllMods()
			if err != nil {
				ui.Error.Printf("Failed to update all files: %v\n", err)
				os.Exit(1)
			}

			ui.Muted.Println("Checking for updates...")
			search := FindUpdates(pack, mods, nil)
			for _, mod := range search.Unsupported {
				ui.Warning.Printf("A supported update system for \"%s\" cannot be found.\n", mod.Name)
			}
			for _, failure := range search.Failures {

				ui.Error.Printf("Failed to check updates for %s: %s\n", failure.Name, failure.Err.Error())
			}
			for _, mod := range search.Pinned {
				ui.Muted.Printf("Update skipped for pinned mod %s\n", mod.Name)
			}

			if len(search.Offers) == 0 {
				if failedChecks := search.FailedChecks(); failedChecks > 0 {

					noun := "files"
					if failedChecks == 1 {
						noun = "file"
					}
					ui.Warning.Printf("No updates found, but %d %s could not be checked.\n", failedChecks, noun)
					return
				}
				ui.Success.Println("All files are up to date!")
				return
			}

			ui.Bold.Println("Updates found:")
			for _, offer := range search.Offers {
				fmt.Printf("%s: %s\n", ui.Bold.Sprint(offer.Mod.Name), StyleUpdate(offer.Change))
			}

			if !cmdshared.PromptYesNo("Do you want to update? [Y/n]: ") {
				ui.Warning.Println("Cancelled!")
				return
			}

			_, errs := ApplyUpdates(&index, search.Offers)
			for _, err := range errs {

				ui.Error.Println(err.Error())
			}
		} else {
			if len(args) < 1 || len(args[0]) == 0 {
				ui.Error.Println("Must specify a valid file, or use the --all flag!")
				os.Exit(1)
			}
			modPath := findMod(index, args[0])
			modData, err := core.LoadMod(modPath)
			if err != nil {
				ui.Error.Println(err)
				os.Exit(1)
			}
			if modData.Pin {
				ui.Error.Println("Version is pinned; run the unpin command to allow updating")
				os.Exit(1)
			}
			singleUpdatedName = modData.Name
			updaterFound := false
			for k := range modData.Update {
				updater, ok := core.Updaters[k]
				if !ok {
					continue
				}
				updaterFound = true

				check, err := updater.CheckUpdate([]*core.Mod{&modData}, pack)
				if err != nil {
					ui.Error.Println(err)
					os.Exit(1)
				}
				if len(check) != 1 {
					ui.Error.Println("Invalid update check response")
					os.Exit(1)
				}

				if check[0].Error != nil {
					ui.Error.Printf("Failed to check updates for %s: %s\n", modData.Name, check[0].Error.Error())
					os.Exit(1)
				}

				if check[0].UpdateAvailable {
					ui.Info.Printf("Update available: %s\n", StyleUpdate(check[0].UpdateString))

					err = updater.DoUpdate([]*core.Mod{&modData}, []interface{}{check[0].CachedState})
					if err != nil {
						ui.Error.Println(err)
						os.Exit(1)
					}

					format, hash, err := modData.Write()
					if err != nil {
						ui.Error.Println(err)
						os.Exit(1)
					}
					err = index.RefreshFileWithHash(modPath, format, hash, true)
					if err != nil {
						ui.Error.Println(err)
						os.Exit(1)
					}
				} else {
					ui.Success.Printf("\"%s\" is already up to date!\n", ui.Bold.Sprint(modData.Name))
					return
				}

				break
			}
			if !updaterFound {

				ui.Error.Println("A supported update system for \"" + modData.Name + "\" cannot be found.")
				os.Exit(1)
			}
		}

		err = index.Write()
		if err != nil {
			ui.Error.Println(err)
			os.Exit(1)
		}
		err = pack.UpdateIndexHash()
		if err != nil {
			ui.Error.Println(err)
			os.Exit(1)
		}
		err = pack.Write()
		if err != nil {
			ui.Error.Println(err)
			os.Exit(1)
		}
		if viper.GetBool("update.all") {
			ui.Success.Println("Files updated!")
		} else {
			ui.Success.Printf("\"%s\" updated!\n", ui.Bold.Sprint(singleUpdatedName))
		}
	},
}

UpdateCmd represents the update command

Functions

func Add

func Add(newCommand *cobra.Command)

Add adds a new command as a subcommand to packwiz

func ApplyUpdates

func ApplyUpdates(index *core.Index, offers []UpdateOffer) (updated []*core.Mod, errs []error)

ApplyUpdates updates the mods of the offers, each by its source, and writes their metadata files and puts them in the index, which is for the caller to write along with the pack (see core.Pack.SaveIndex). It returns the mods that were updated and the errors of what wasn't: an update that fails doesn't stop the others.

func CreatePack

func CreatePack(pack NewPack) error

CreatePack creates a pack in the current directory: pack.toml, and the index of the files it has, as "packwiz init" does without asking anything. It says nothing on the terminal. It won't replace a pack that is there.

func DefaultPackName

func DefaultPackName() string

DefaultPackName is what a pack in the current directory is called if it isn't told otherwise, going by the name of the folder, or "" if that isn't known.

func Execute

func Execute()

Execute starts the root command for packwiz

func FilterByKind

func FilterByKind(mods []*core.Mod, only string) []*core.Mod

FilterByKind keeps the mods that are main mods (only is OnlyMain) or are dependencies of others (OnlyDependencies), as "packwiz list --only" lists them. It works in place, so the mods that it is given are not to be used as they were.

func FilterBySide

func FilterBySide(mods []*core.Mod, side string) []*core.Mod

FilterBySide keeps the mods that run on a side, as "packwiz list --side" lists them: those that are on it, and those that are on both, which is what a mod with no side is taken to be. It works in place, as FilterByKind does.

func LoaderVersion

func LoaderVersion(loader core.ModLoaderComponent, mcVersion, chosen string) string

LoaderVersion is the version of a mod loader as a pack records it, given the one that was chosen for a Minecraft version. NeoForge reused Forge's version-prefixing format (prefixed with the supported Minecraft version), but only during the 1.20.1 days; they've since switched formats.

func LoaderVersions

func LoaderVersions(loader, mcVersion string) (*core.ModLoaderVersions, error)

LoaderVersions lists the versions of a mod loader that are for a Minecraft version, and which of them is the latest. It asks the network. loader is one of the names in core.ModLoaders.

func RenderModList

func RenderModList(pack core.Pack, index core.Index, mods []*core.Mod) (string, error)

RenderModList makes the markdown list of the mods, as "packwiz list --save" writes it.

func Root

func Root() *cobra.Command

Root returns the root command, for tests of what is registered on it from other packages.

func SaveModList

func SaveModList(pack core.Pack, index core.Index, mods []*core.Mod) (string, error)

SaveModList writes the markdown list of the mods to the file that "packwiz list --save" writes to when it isn't told where, in the pack's folder, and returns where that is. It says nothing: it is for what has the terminal to itself.

func SaveServerModList

func SaveServerModList(pack core.Pack, index core.Index, mods []*core.Mod) (string, error)

SaveServerModList writes the markdown list of the mods that run on the server (of all the pack's mods) to the file that "packwiz list --save --side server" writes to when it isn't told where (core.ServerModListFile), making its folder if it has to, and returns where that is. It says nothing, as SaveModList doesn't.

func ServerModList

func ServerModList(mods []*core.Mod) []*core.Mod

ServerModList is the mods of the pack that run on the server, as "packwiz list --side server" lists them, in a new slice.

func SetDefault

func SetDefault(long string, run func())

SetDefault sets what running packwiz with no arguments does, and the help that says so (a command package registers it, as the commands are: cmd can't import them). Arguments that aren't a command are still an unknown command, not run.

func SortMods

func SortMods(mods []*core.Mod)

SortMods puts mods in alphabetical order of their names, ignoring case, which is the order they are listed in.

func StyleUpdate

func StyleUpdate(update string) string

StyleUpdate shows what an updater says an update is, which is usually "old -> new", with the old and the new set apart

Types

type InitCheck

type InitCheck struct {
	// Created lists the files that were missing and have been made
	Created []string
	// Errors are what is wrong with a file and can't be fixed without a decision, so the pack can't be used as it is
	Errors []string
	// Warnings are problems that don't stop the pack from being used
	Warnings []string
}

InitCheck is what "packwiz init" finds when it is run where a pack already is: it asks nothing and changes nothing the person chose, only checking the files that make a pack (pack.toml and its index) and making any that are missing.

func CheckExistingPack

func CheckExistingPack(quiet bool) (InitCheck, error)

CheckExistingPack checks the pack in the current directory and creates the index file it names if that is missing, as "packwiz init" does when there is a pack already. It never changes what pack.toml says, except to record the hash of an index it made, and it doesn't look at the mods. With quiet, nothing is printed, not even the progress of the refresh of an index that is made. The error is for a failure to read or write, where Errors are for what is wrong with the files.

type NewPack

type NewPack struct {
	Name, Author, Version string
	// MCVersion is the Minecraft version, which isn't checked here
	MCVersion string
	// Loader is the name of the mod loader, which is one of the names in core.ModLoaders, or "none" or empty for no mod
	// loader, and LoaderVersion the version of it
	Loader, LoaderVersion string
	// IndexFile is where the index is, relative to pack.toml
	IndexFile string
}

NewPack is what a pack is created with.

type UpdateFailure

type UpdateFailure struct {
	// Name is what couldn't be checked: a mod's name, or the name of a source if it failed for all of its mods
	Name string
	Err  error
	// Count is how many mods this is for: one, or all of the mods of a source that failed as a whole
	Count int
}

UpdateFailure is a check for an update that couldn't be made.

type UpdateOffer

type UpdateOffer struct {
	// Mod is the mod as it is now
	Mod *core.Mod
	// Source is what found the update, the name of an updater in core.Updaters, and does it
	Source string
	// Change says what the update is, usually "old -> new" (see core.UpdateCheck)
	Change string
	// contains filtered or unexported fields
}

UpdateOffer is a new version of a mod, which it can be updated to.

type UpdateSearch

type UpdateSearch struct {
	// Offers are the updates that can be made, in the order of their sources and then of the mods they were given in
	Offers []UpdateOffer
	// Failures are the checks that couldn't be made, which isn't the same as there being no update
	Failures []UpdateFailure
	// Pinned are the mods that have an update that isn't offered, as they are pinned
	Pinned []*core.Mod
	// Unsupported are the mods that no source that the pack has can update
	Unsupported []*core.Mod
	// Checked is how many checks were made, which is one for each mod and source that can update it
	Checked int
}

UpdateSearch is what looking for updates to some mods found.

func FindUpdates

func FindUpdates(pack core.Pack, mods []*core.Mod, progress func(source string)) UpdateSearch

FindUpdates looks for an update to each of the mods, by asking their sources, as "packwiz update --all" does. It changes nothing, and says nothing: what it finds is returned, for the caller to show. progress, if it isn't nil, is told which source is being asked, as that is what takes the time.

func (UpdateSearch) FailedChecks

func (s UpdateSearch) FailedChecks() int

FailedChecks is how many mods there is no answer for.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL