-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/vpkflags: Implement vpkflags command
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 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
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,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) | ||
} | ||
} |