updated and fully freestanding
This commit is contained in:
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/p9c/pod/pkg/util/interrupt"
|
||||
"github.com/p9c/interrupt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
18
go.mod
Normal file
18
go.mod
Normal file
@@ -0,0 +1,18 @@
|
||||
module github.com/p9c/interrupt
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.4.0 // indirect
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/p9c/log v0.0.6
|
||||
github.com/p9c/qu v0.0.3
|
||||
github.com/stretchr/testify v1.6.1 // indirect
|
||||
go.uber.org/atomic v1.7.0
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
gopkg.in/src-d/go-git.v4 v4.13.1
|
||||
)
|
||||
103
go.sum
Normal file
103
go.sum
Normal file
@@ -0,0 +1,103 @@
|
||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
|
||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
|
||||
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
|
||||
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/gookit/color v1.3.8 h1:w2WcSwaCa1ojRWO60Mm4GJUJomBNKR9G+x9DwaaCL1c=
|
||||
github.com/gookit/color v1.3.8/go.mod h1:R3ogXq2B9rTbXoSHJ1HyUVAZ3poOJHpd9nQmyGZsfvQ=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
|
||||
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
|
||||
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/p9c/log v0.0.5/go.mod h1:BQGlR1Qg9Mylv6AQu3HGC2hpdR07gvYN2KlpYLMRzVI=
|
||||
github.com/p9c/log v0.0.6 h1:+o2u/IAEDcItmXzVYQEguMTOYQARlYX5eytNbX6feQE=
|
||||
github.com/p9c/log v0.0.6/go.mod h1:BQGlR1Qg9Mylv6AQu3HGC2hpdR07gvYN2KlpYLMRzVI=
|
||||
github.com/p9c/qu v0.0.3 h1:ZrEziZcSvgAG8+eRsbGTz6mhWleFmX32i8GkDiv2bHU=
|
||||
github.com/p9c/qu v0.0.3/go.mod h1:98UKWfn5re2h1Vfb/qMJV/2MpRQP9ILYbjpON3V+eRE=
|
||||
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
|
||||
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
|
||||
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg=
|
||||
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
|
||||
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg=
|
||||
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g=
|
||||
gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE=
|
||||
gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8=
|
||||
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
|
||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
40
log.go
40
log.go
@@ -1,42 +1,8 @@
|
||||
package interrupt
|
||||
|
||||
import (
|
||||
"github.com/p9c/pod/pkg/logg"
|
||||
"github.com/p9c/log"
|
||||
"github.com/p9c/qu/version"
|
||||
)
|
||||
|
||||
var subsystem = logg.AddLoggerSubsystem()
|
||||
var F, E, W, I, D, T logg.LevelPrinter = logg.GetLogPrinterSet(subsystem)
|
||||
|
||||
func init() {
|
||||
// to filter out this package, uncomment the following
|
||||
// var _ = logg.AddFilteredSubsystem(subsystem)
|
||||
|
||||
// to highlight this package, uncomment the following
|
||||
// var _ = logg.AddHighlightedSubsystem(subsystem)
|
||||
|
||||
// these are here to test whether they are working
|
||||
// F.Ln("F.Ln")
|
||||
// E.Ln("E.Ln")
|
||||
// W.Ln("W.Ln")
|
||||
// I.Ln("I.Ln")
|
||||
// D.Ln("D.Ln")
|
||||
// F.Ln("T.Ln")
|
||||
// F.F("%s", "F.F")
|
||||
// E.F("%s", "E.F")
|
||||
// W.F("%s", "W.F")
|
||||
// I.F("%s", "I.F")
|
||||
// D.F("%s", "D.F")
|
||||
// T.F("%s", "T.F")
|
||||
// F.C(func() string { return "F.C" })
|
||||
// E.C(func() string { return "E.C" })
|
||||
// W.C(func() string { return "W.C" })
|
||||
// I.C(func() string { return "I.C" })
|
||||
// D.C(func() string { return "D.C" })
|
||||
// T.C(func() string { return "T.C" })
|
||||
// F.C(func() string { return "F.C" })
|
||||
// E.Chk(errors.New("E.Chk"))
|
||||
// W.Chk(errors.New("W.Chk"))
|
||||
// I.Chk(errors.New("I.Chk"))
|
||||
// D.Chk(errors.New("D.Chk"))
|
||||
// T.Chk(errors.New("T.Chk"))
|
||||
}
|
||||
var F, E, W, I, D, T = log.GetLogPrinterSet(log.AddLoggerSubsystem(version.PathBase))
|
||||
|
||||
2
main.go
2
main.go
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
uberatomic "go.uber.org/atomic"
|
||||
|
||||
"github.com/p9c/pod/pkg/util/qu"
|
||||
"github.com/p9c/qu"
|
||||
|
||||
"github.com/kardianos/osext"
|
||||
)
|
||||
|
||||
8
version/update/log.go
Normal file
8
version/update/log.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/p9c/log"
|
||||
"github.com/p9c/qu/version"
|
||||
)
|
||||
|
||||
var F, E, W, I, D, T = log.GetLogPrinterSet(log.AddLoggerSubsystem(version.PathBase))
|
||||
152
version/update/main.go
Normal file
152
version/update/main.go
Normal file
@@ -0,0 +1,152 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gopkg.in/src-d/go-git.v4"
|
||||
"gopkg.in/src-d/go-git.v4/plumbing"
|
||||
"gopkg.in/src-d/go-git.v4/plumbing/storer"
|
||||
)
|
||||
|
||||
var (
|
||||
URL string
|
||||
GitRef string
|
||||
GitCommit string
|
||||
BuildTime string
|
||||
Tag string
|
||||
)
|
||||
|
||||
func main() {
|
||||
BuildTime = time.Now().Format(time.RFC3339)
|
||||
var cwd string
|
||||
var e error
|
||||
if cwd, e = os.Getwd(); e != nil {
|
||||
return
|
||||
}
|
||||
var repo *git.Repository
|
||||
if repo, e = git.PlainOpen(cwd); e != nil {
|
||||
return
|
||||
}
|
||||
var rr []*git.Remote
|
||||
if rr, e = repo.Remotes(); e != nil {
|
||||
return
|
||||
}
|
||||
for i := range rr {
|
||||
rs := rr[i].String()
|
||||
if strings.HasPrefix(rs, "origin") {
|
||||
rss := strings.Split(rs, "git@")
|
||||
if len(rss) > 1 {
|
||||
rsss := strings.Split(rss[1], ".git")
|
||||
URL = strings.ReplaceAll(rsss[0], ":", "/")
|
||||
break
|
||||
}
|
||||
rss = strings.Split(rs, "https://")
|
||||
if len(rss) > 1 {
|
||||
rsss := strings.Split(rss[1], ".git")
|
||||
URL = rsss[0]
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
var rh *plumbing.Reference
|
||||
if rh, e = repo.Head(); e != nil {
|
||||
return
|
||||
}
|
||||
rhs := rh.Strings()
|
||||
GitRef = rhs[0]
|
||||
GitCommit = rhs[1]
|
||||
var rt storer.ReferenceIter
|
||||
if rt, e = repo.Tags(); e != nil {
|
||||
return
|
||||
}
|
||||
var maxVersion int
|
||||
var maxString string
|
||||
var maxIs bool
|
||||
if e = rt.ForEach(
|
||||
func(pr *plumbing.Reference) (e error) {
|
||||
prs := strings.Split(pr.String(), "/")[2]
|
||||
if strings.HasPrefix(prs, "v") {
|
||||
var va [3]int
|
||||
_, _ = fmt.Sscanf(prs, "v%d.%d.%d", &va[0], &va[1], &va[2])
|
||||
vn := va[0]*1000000 + va[1]*1000 + va[2]
|
||||
if maxVersion < vn {
|
||||
maxVersion = vn
|
||||
maxString = prs
|
||||
}
|
||||
if pr.Hash() == rh.Hash() {
|
||||
maxIs = true
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
); e != nil {
|
||||
return
|
||||
}
|
||||
if !maxIs {
|
||||
maxString += "+"
|
||||
}
|
||||
Tag = maxString
|
||||
_, file, _, _ := runtime.Caller(0)
|
||||
// fmt.Fprintln(os.Stderr, "file", file)
|
||||
urlSplit := strings.Split(URL, "/")
|
||||
// fmt.Fprintln(os.Stderr, "urlSplit", urlSplit)
|
||||
baseFolder := urlSplit[len(urlSplit)-1]
|
||||
// fmt.Fprintln(os.Stderr, "baseFolder", baseFolder)
|
||||
splitPath := strings.Split(file, baseFolder)
|
||||
// fmt.Fprintln(os.Stderr, "splitPath", splitPath)
|
||||
PathBase := filepath.Join(splitPath[0], baseFolder) + string(filepath.Separator)
|
||||
PathBase = strings.ReplaceAll(PathBase, "\\", "\\\\")
|
||||
// fmt.Fprintln(os.Stderr, "PathBase", PathBase)
|
||||
versionFile := `package version
|
||||
|
||||
import "fmt"
|
||||
|
||||
var (
|
||||
|
||||
// URL is the git URL for the repository
|
||||
URL = "%s"
|
||||
// GitRef is the gitref, as in refs/heads/branchname
|
||||
GitRef = "%s"
|
||||
// GitCommit is the commit hash of the current HEAD
|
||||
GitCommit = "%s"
|
||||
// BuildTime stores the time when the current binary was built
|
||||
BuildTime = "%s"
|
||||
// Tag lists the Tag on the build, adding a + to the newest Tag if the commit is
|
||||
// not that commit
|
||||
Tag = "%s"
|
||||
// PathBase is the path base returned from runtime caller
|
||||
PathBase = "%s"
|
||||
)
|
||||
|
||||
// Get returns a pretty printed version information string
|
||||
func Get() string {
|
||||
return fmt.Sprint(
|
||||
"Repository Information\n"+
|
||||
" git repository: "+URL+"\n",
|
||||
" branch: "+GitRef+"\n"+
|
||||
" commit: "+GitCommit+"\n"+
|
||||
" built: "+BuildTime+"\n"+
|
||||
" Tag: "+Tag+"\n",
|
||||
)
|
||||
}
|
||||
`
|
||||
versionFileOut := fmt.Sprintf(
|
||||
versionFile,
|
||||
URL,
|
||||
GitRef,
|
||||
GitCommit,
|
||||
BuildTime,
|
||||
Tag,
|
||||
PathBase,
|
||||
)
|
||||
if e = ioutil.WriteFile("version/version.go", []byte(versionFileOut), 0666); E.Chk(e) {
|
||||
}
|
||||
return
|
||||
}
|
||||
32
version/version.go
Normal file
32
version/version.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package version
|
||||
|
||||
import "fmt"
|
||||
|
||||
var (
|
||||
|
||||
// URL is the git URL for the repository
|
||||
URL = "github.com/p9c/interrupt"
|
||||
// GitRef is the gitref, as in refs/heads/branchname
|
||||
GitRef = "refs/heads/main"
|
||||
// GitCommit is the commit hash of the current HEAD
|
||||
GitCommit = "568956448c87f6147be12234760f99779ede0304"
|
||||
// BuildTime stores the time when the current binary was built
|
||||
BuildTime = "2021-04-15T02:19:31+02:00"
|
||||
// Tag lists the Tag on the build, adding a + to the newest Tag if the commit is
|
||||
// not that commit
|
||||
Tag = "v0.0.1"
|
||||
// PathBase is the path base returned from runtime caller
|
||||
PathBase = "/home/loki/src/github.com/p9c/interrupt/"
|
||||
)
|
||||
|
||||
// Get returns a pretty printed version information string
|
||||
func Get() string {
|
||||
return fmt.Sprint(
|
||||
"Repository Information\n"+
|
||||
" git repository: "+URL+"\n",
|
||||
" branch: "+GitRef+"\n"+
|
||||
" commit: "+GitCommit+"\n"+
|
||||
" built: "+BuildTime+"\n"+
|
||||
" Tag: "+Tag+"\n",
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user