-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pin and unpin commands/updated update command to work with pin & …
…unpin (#234) * Add pin and unpin commands/updated update command to work with pin & unpin * Inline cobra functions
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/packwiz/packwiz/core" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func pinMod(cmd *cobra.Command, args []string, pinned bool) { | ||
fmt.Println("Loading modpack...") | ||
pack, err := core.LoadPack() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
index, err := pack.LoadIndex() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
modPath, ok := index.FindMod(args[0]) | ||
if !ok { | ||
fmt.Println("Can't find this file; please ensure you have run packwiz refresh and use the name of the .pw.toml file (defaults to the project slug)") | ||
os.Exit(1) | ||
} | ||
modData, err := core.LoadMod(modPath) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
modData.Pin = pinned | ||
format, hash, err := modData.Write() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
err = index.RefreshFileWithHash(modPath, format, hash, true) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
err = index.Write() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
err = pack.UpdateIndexHash() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
err = pack.Write() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
message := "pinned" | ||
if !pinned { | ||
message = "unpinned" | ||
} | ||
fmt.Printf("%s %s successfully!\n", args[0], message) | ||
} | ||
|
||
// pinCmd represents the pin command | ||
var pinCmd = &cobra.Command{ | ||
Use: "pin", | ||
Short: "Pin a mod to the current version", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
pinMod(cmd, args, true) | ||
}, | ||
} | ||
|
||
// unpinCmd represents the unpin command | ||
var unpinCmd = &cobra.Command{ | ||
Use: "unpin", | ||
Short: "Unpin a mod from the current version", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
pinMod(cmd, args, false) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(pinCmd) | ||
rootCmd.AddCommand(unpinCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters