-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
239 additions
and
12 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
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 cmd | ||
|
||
import ( | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
type openCmd struct { | ||
parent *flag.FlagSet | ||
cmd *flag.FlagSet | ||
archDiagramPath *string | ||
} | ||
|
||
func NewOpenCmd(parent *flag.FlagSet) (*openCmd, error) { | ||
nCmd := &openCmd{ | ||
parent: parent, | ||
} | ||
|
||
nCmd.cmd = flag.NewFlagSet("normal", flag.ExitOnError) | ||
nCmd.archDiagramPath = nCmd.cmd.String("p", "", fmt.Sprintf( | ||
"[required] target arch diagram path \n(e.g. %s)", "dddplayer/arch.dot")) | ||
|
||
err := nCmd.cmd.Parse(parent.Args()[1:]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return nCmd, nil | ||
} | ||
|
||
func (oc *openCmd) Usage() { | ||
oc.cmd.Usage() | ||
} | ||
|
||
func (oc *openCmd) Run() error { | ||
if *oc.archDiagramPath == "" { | ||
oc.cmd.Usage() | ||
return errors.New("please specify a target arch diagram path") | ||
} | ||
|
||
_, err := os.Stat(*oc.archDiagramPath) | ||
if os.IsNotExist(err) { | ||
return fmt.Errorf("file %s does not exist", *oc.archDiagramPath) | ||
} | ||
|
||
dotStr, err := os.ReadFile(*oc.archDiagramPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return open(string(dotStr)) | ||
} |
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
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,140 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"runtime/debug" | ||
"sync" | ||
) | ||
|
||
type versionCmd struct { | ||
parent *flag.FlagSet | ||
cmd *flag.FlagSet | ||
} | ||
|
||
func NewVersionCmd(parent *flag.FlagSet) (*versionCmd, error) { | ||
nCmd := &versionCmd{ | ||
parent: parent, | ||
} | ||
|
||
nCmd.cmd = flag.NewFlagSet("version", flag.ExitOnError) | ||
err := nCmd.cmd.Parse(parent.Args()[1:]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return nCmd, nil | ||
} | ||
|
||
func (oc *versionCmd) Usage() { | ||
oc.cmd.Usage() | ||
} | ||
|
||
func (oc *versionCmd) Run() error { | ||
fmt.Println(BuildVersionString()) | ||
return nil | ||
} | ||
|
||
func BuildVersionString() string { | ||
// program := "Hugo Static Site Generator" | ||
program := "dddplayer" | ||
|
||
version := "v" + CurrentVersion.String() | ||
|
||
bi := getBuildInfo() | ||
if bi == nil { | ||
return version | ||
} | ||
if bi.Revision != "" { | ||
version += "-" + bi.Revision | ||
} | ||
|
||
osArch := bi.GoOS + "/" + bi.GoArch | ||
|
||
date := bi.RevisionTime | ||
if date == "" { | ||
// Accept vendor-specified build date if .git/ is unavailable. | ||
date = "unknown" | ||
} | ||
|
||
versionString := fmt.Sprintf("%s %s %s BuildDate=%s", | ||
program, version, osArch, date) | ||
|
||
return versionString | ||
} | ||
|
||
var ( | ||
bInfo *buildInfo | ||
bInfoInit sync.Once | ||
) | ||
|
||
type buildInfo struct { | ||
VersionControlSystem string | ||
Revision string | ||
RevisionTime string | ||
Modified bool | ||
|
||
GoOS string | ||
GoArch string | ||
|
||
*debug.BuildInfo | ||
} | ||
|
||
func getBuildInfo() *buildInfo { | ||
bInfoInit.Do(func() { | ||
bi, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return | ||
} | ||
|
||
bInfo = &buildInfo{BuildInfo: bi} | ||
|
||
for _, s := range bInfo.Settings { | ||
switch s.Key { | ||
case "vcs": | ||
bInfo.VersionControlSystem = s.Value | ||
case "vcs.revision": | ||
bInfo.Revision = s.Value | ||
case "vcs.time": | ||
bInfo.RevisionTime = s.Value | ||
case "vcs.modified": | ||
bInfo.Modified = s.Value == "true" | ||
case "GOOS": | ||
bInfo.GoOS = s.Value | ||
case "GOARCH": | ||
bInfo.GoArch = s.Value | ||
} | ||
} | ||
}) | ||
|
||
return bInfo | ||
} | ||
|
||
var CurrentVersion = Version{ | ||
Major: 0, | ||
Minor: 2, | ||
PatchLevel: 0, | ||
Suffix: "", | ||
} | ||
|
||
// Version represents the Hugo build version. | ||
type Version struct { | ||
Major int | ||
|
||
Minor int | ||
|
||
// Increment this for bug releases | ||
PatchLevel int | ||
|
||
// HugoVersionSuffix is the suffix used in the Hugo version string. | ||
// It will be blank for release versions. | ||
Suffix string | ||
} | ||
|
||
func (v Version) String() string { | ||
return version(v.Major, v.Minor, v.PatchLevel, v.Suffix) | ||
} | ||
|
||
func version(major, minor, patch int, suffix string) string { | ||
return fmt.Sprintf("%d.%d.%d%s", major, minor, patch, suffix) | ||
} |