add init to initialize ./scripts/ with examples

This commit is contained in:
AJ ONeal 2020-10-23 15:56:49 -06:00
parent 54ce54ad72
commit 9280224acb
9 changed files with 60 additions and 20 deletions

View File

@ -1,4 +0,0 @@
// +build !dev
//go:generate go run -mod vendor github.com/shurcooL/vfsgen/cmd/vfsgendev -source="git.rootprojects.org/root/gitdeploy/assets".Assets
package assets

View File

@ -0,0 +1,4 @@
// +build !dev
//go:generate go run -mod vendor github.com/shurcooL/vfsgen/cmd/vfsgendev -source="git.rootprojects.org/root/gitdeploy/assets/examples".Assets
package examples

View File

@ -0,0 +1,8 @@
// +build dev
package examples
import "net/http"
// Assets is the public file system which should be served by http
var Assets http.FileSystem = http.Dir("../../examples")

4
assets/public/assets.go Normal file
View File

@ -0,0 +1,4 @@
// +build !dev
//go:generate go run -mod vendor github.com/shurcooL/vfsgen/cmd/vfsgendev -source="git.rootprojects.org/root/gitdeploy/assets/public".Assets
package public

View File

@ -1,8 +1,8 @@
// +build dev // +build dev
package assets package public
import "net/http" import "net/http"
// Assets is the public file system which should be served by http // Assets is the public file system which should be served by http
var Assets http.FileSystem = http.Dir("../public") var Assets http.FileSystem = http.Dir("../../public")

3
go.mod
View File

@ -4,10 +4,9 @@ go 1.15
require ( require (
git.rootprojects.org/root/go-gitver/v2 v2.0.2 git.rootprojects.org/root/go-gitver/v2 v2.0.2
git.rootprojects.org/root/vfscopy v1.0.0
github.com/go-chi/chi v4.1.2+incompatible github.com/go-chi/chi v4.1.2+incompatible
github.com/google/go-github/v32 v32.1.0 github.com/google/go-github/v32 v32.1.0
github.com/joho/godotenv v1.3.0 github.com/joho/godotenv v1.3.0
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346 // indirect
) )

17
go.sum
View File

@ -1,5 +1,7 @@
git.rootprojects.org/root/go-gitver/v2 v2.0.2 h1:T+Je13wrY1jz4OPJF98HnuCNp6n2Xe2uK6/NNF6a4+0= git.rootprojects.org/root/go-gitver/v2 v2.0.2 h1:T+Je13wrY1jz4OPJF98HnuCNp6n2Xe2uK6/NNF6a4+0=
git.rootprojects.org/root/go-gitver/v2 v2.0.2/go.mod h1:ur82M/jZcvr1WWihyVtNEgDBqIjo22o56wcVHeVJFh8= git.rootprojects.org/root/go-gitver/v2 v2.0.2/go.mod h1:ur82M/jZcvr1WWihyVtNEgDBqIjo22o56wcVHeVJFh8=
git.rootprojects.org/root/vfscopy v1.0.0 h1:djPpb/+4wf5DG2ZKyq6ih67JdLNGZxoIlDZddAil/LI=
git.rootprojects.org/root/vfscopy v1.0.0/go.mod h1:fYHopt0phBfgOfuOJbLnseemp9tsPL+/kwnxtLJxlnY=
github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec=
github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -22,19 +24,22 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 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-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/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-20190215142949-d0b11bdaac8a/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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
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-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346 h1:hzJjkvxUIF3bSt+v8N5tBQNx/605vszZJ+3XsIamzZo= golang.org/x/tools v0.0.0-20201023174141-c8cfbd0f21e6 h1:rbvTkL9AkFts1cgI78+gG6Yu1pwaqX6hjSJAatB78E4=
golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.0.0-20201023174141-c8cfbd0f21e6/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

30
main.go
View File

@ -14,7 +14,9 @@ import (
"strings" "strings"
"time" "time"
"git.rootprojects.org/root/gitdeploy/assets" "git.rootprojects.org/root/vfscopy"
"git.rootprojects.org/root/gitdeploy/assets/public"
"git.rootprojects.org/root/gitdeploy/assets/examples"
"git.rootprojects.org/root/gitdeploy/internal/options" "git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks" "git.rootprojects.org/root/gitdeploy/internal/webhooks"
@ -122,7 +124,29 @@ func main() {
return return
case "init": case "init":
_ = initFlags.Parse(args[2:]) _ = initFlags.Parse(args[2:])
fmt.Fprintf(os.Stderr, "%s init: not implemented\n", name) vfs := vfscopy.NewVFS(examples.Assets)
_, err := os.Open("scripts")
if nil == err {
fmt.Fprintf(os.Stderr, "./scripts already exists\n")
os.Exit(1)
return
}
fmt.Println("Copying ...")
if err := vfscopy.CopyAll(vfs, ".", "./scripts", vfscopy.Options {
Skip: func (path string) (bool, error) {
f, _ := vfs.Open(path)
fi, _ := f.Stat()
if !fi.IsDir() {
fmt.Println(" scripts/" + path)
}
return false, nil
},
}); nil != err {
fmt.Fprintf(os.Stderr, "error initializing ./scripts directory\n")
os.Exit(1)
return
}
fmt.Println("Done.")
os.Exit(0) os.Exit(0)
return return
case "run": case "run":
@ -210,7 +234,7 @@ func serve() {
r.Use(middleware.Recoverer) r.Use(middleware.Recoverer)
var staticHandler http.HandlerFunc var staticHandler http.HandlerFunc
pub := http.FileServer(assets.Assets) pub := http.FileServer(public.Assets)
if len(runOpts.ServePath) > 0 { if len(runOpts.ServePath) > 0 {
// try the user-provided directory first, then fallback to the built-in // try the user-provided directory first, then fallback to the built-in

6
vendor/modules.txt vendored
View File

@ -2,6 +2,9 @@
## explicit ## explicit
git.rootprojects.org/root/go-gitver/v2 git.rootprojects.org/root/go-gitver/v2
git.rootprojects.org/root/go-gitver/v2/gitver git.rootprojects.org/root/go-gitver/v2/gitver
# git.rootprojects.org/root/vfscopy v1.0.0
## explicit
git.rootprojects.org/root/vfscopy
# github.com/go-chi/chi v4.1.2+incompatible # github.com/go-chi/chi v4.1.2+incompatible
## explicit ## explicit
github.com/go-chi/chi github.com/go-chi/chi
@ -16,7 +19,6 @@ github.com/google/go-querystring/query
github.com/joho/godotenv github.com/joho/godotenv
github.com/joho/godotenv/autoload github.com/joho/godotenv/autoload
# github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 # github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
## explicit
github.com/shurcooL/httpfs/vfsutil github.com/shurcooL/httpfs/vfsutil
# github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 # github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
## explicit ## explicit
@ -30,5 +32,3 @@ golang.org/x/crypto/openpgp/elgamal
golang.org/x/crypto/openpgp/errors golang.org/x/crypto/openpgp/errors
golang.org/x/crypto/openpgp/packet golang.org/x/crypto/openpgp/packet
golang.org/x/crypto/openpgp/s2k golang.org/x/crypto/openpgp/s2k
# golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346
## explicit