-
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, cmd/tf2vpk: Start working on new CLI
- Loading branch information
Showing
4 changed files
with
106 additions
and
1 deletion.
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,30 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Version = "unknown" | ||
|
||
func Execute() { | ||
root.Execute() | ||
} | ||
|
||
var root = &cobra.Command{ | ||
Use: "tf2vpk", | ||
Short: "Manipulates Respawn VPK archives.", | ||
} | ||
|
||
var version = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the current version.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println(root.Name(), Version) | ||
}, | ||
} | ||
|
||
func init() { | ||
root.AddCommand(version) | ||
} |
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,63 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"runtime/debug" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/pg9182/tf2vpk/cmd" | ||
) | ||
|
||
// alias tf2vpk='go install ./cmd/tf2vpk && source <(~/go/bin/tf2vpk completion bash) && ~/go/bin/tf2vpk' | ||
|
||
func main() { | ||
if v, err := version(); err != nil { | ||
fmt.Fprintf(os.Stderr, "warning: failed to get version: %v\n", err) | ||
} else { | ||
cmd.Version = v | ||
} | ||
cmd.Execute() | ||
} | ||
|
||
func version() (version string, err error) { | ||
version = "unknown" | ||
|
||
var vcs struct { | ||
revision string | ||
time time.Time | ||
modified bool | ||
} | ||
if bi, ok := debug.ReadBuildInfo(); ok { | ||
for _, s := range bi.Settings { | ||
switch s.Key { | ||
case "vcs.revision": | ||
v := s.Value | ||
if len(v) < 20 { | ||
return version, fmt.Errorf("parse %s %q: too short", s.Key, s.Value) | ||
} | ||
vcs.revision = v | ||
case "vcs.time": | ||
v, err := time.ParseInLocation(time.RFC3339Nano, s.Value, time.UTC) | ||
if err != nil { | ||
return version, fmt.Errorf("parse %s %q: %w", s.Key, s.Value, err) | ||
} | ||
vcs.time = v | ||
case "vcs.modified": | ||
v, err := strconv.ParseBool(s.Value) | ||
if err != nil { | ||
return version, fmt.Errorf("parse %s %q: %w", s.Key, s.Value, err) | ||
} | ||
vcs.modified = v | ||
} | ||
} | ||
} | ||
if len(vcs.revision) != 0 { | ||
version = vcs.revision[:7] | ||
if vcs.modified { | ||
version += " (modified)" | ||
} | ||
} | ||
return version, nil | ||
} |
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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/pg9182/tf2lzham v0.0.8 h1:jlsqardylTJRMDAIUiqSCXVrZiiXSJXgG2zR9gm1CQc= | ||
github.com/pg9182/tf2lzham v0.0.8/go.mod h1:jmffn2XEql5BvNnEChzXvzBV0p/4cfs+jW0ngPXTvoQ= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= | ||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
github.com/tetratelabs/wazero v1.7.0 h1:jg5qPydno59wqjpGrHph81lbtHzTrWzwwtD4cD88+hQ= | ||
github.com/tetratelabs/wazero v1.7.0/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |