Skip to content

Commit

Permalink
cmd/vpkflags: Implement vpkflags command
Browse files Browse the repository at this point in the history
  • Loading branch information
pg9182 committed Apr 14, 2024
1 parent 2349381 commit 87ad327
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
_ "github.com/pg9182/tf2vpk/cmd/lzham"
_ "github.com/pg9182/tf2vpk/cmd/verify"
_ "github.com/pg9182/tf2vpk/cmd/version"
_ "github.com/pg9182/tf2vpk/cmd/vpkflags"
)

func Execute() {
Expand Down
54 changes: 54 additions & 0 deletions cmd/vpkflags/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package vpkflags

import (
"fmt"
"os"

"github.com/pg9182/tf2vpk"
"github.com/pg9182/tf2vpk/cmd/root"
"github.com/pg9182/tf2vpk/vpkutil"
"github.com/spf13/cobra"
)

var Flags struct {
VPK tf2vpk.ValvePak
Explicit bool
}

var Command = &cobra.Command{
Use: "vpkflags vpk_path",
Short: "Generates a vpkflags file for the specified VPK.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
main()
},
GroupID: root.GroupVPKRepacking.ID,
}

func init() {
root.ArgVPK(&Flags.VPK, Command, -1, false, false, false)
Command.Flags().BoolVarP(&Flags.Explicit, "explicit", "x", false, "do not compute inherited vpkflags; generate one line for each file")
root.Command.AddCommand(Command)
}

func main() {
r, err := tf2vpk.NewReader(Flags.VPK)
if err != nil {
fmt.Fprintf(os.Stderr, "error: open vpk: %v\n", err)
os.Exit(1)
}

var vpkflags vpkutil.VPKFlags
if Flags.Explicit {
err = vpkflags.GenerateExplicit(r.Root)
} else {
err = vpkflags.Generate(r.Root)
}
if err != nil {
fmt.Fprintf(os.Stderr, "error: generate vpkflags: %v\n", err)
os.Exit(1)
}
if _, err := os.Stdout.WriteString(vpkflags.String()); err != nil {
os.Exit(1)
}
}

0 comments on commit 87ad327

Please sign in to comment.