mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
Merge branch 'master' of https://github.com/gogf/gf
This commit is contained in:
@ -65,16 +65,17 @@ func (c *Command) Print() {
|
||||
}
|
||||
}
|
||||
for _, cmd := range c.commands {
|
||||
brief := gstr.Replace(cmd.Brief, "\n", "")
|
||||
// Add "..." to brief for those commands that also have sub-commands.
|
||||
if len(cmd.commands) > 0 {
|
||||
cmd.Brief = gstr.TrimRight(cmd.Brief, ".") + "..."
|
||||
brief = gstr.TrimRight(brief, ".") + "..."
|
||||
}
|
||||
var (
|
||||
spaceLength = maxSpaceLength - len(cmd.Name)
|
||||
wordwrapPrefix = gstr.Repeat(" ", len(prefix+cmd.Name)+spaceLength+4)
|
||||
lineStr = fmt.Sprintf(
|
||||
"%s%s%s%s\n",
|
||||
prefix, cmd.Name, gstr.Repeat(" ", spaceLength+4), gstr.Trim(cmd.Brief),
|
||||
prefix, cmd.Name, gstr.Repeat(" ", spaceLength+4), gstr.Trim(brief),
|
||||
)
|
||||
)
|
||||
lineStr = gstr.WordWrap(lineStr, maxLineChars, "\n"+wordwrapPrefix)
|
||||
@ -102,11 +103,12 @@ func (c *Command) Print() {
|
||||
continue
|
||||
}
|
||||
var (
|
||||
brief = gstr.Trim(gstr.Replace(arg.Brief, "\n", ""))
|
||||
spaceLength = maxSpaceLength - len(arg.Name)
|
||||
wordwrapPrefix = gstr.Repeat(" ", len(prefix+arg.Name)+spaceLength+4)
|
||||
lineStr = fmt.Sprintf(
|
||||
"%s%s%s%s\n",
|
||||
prefix, arg.Name, gstr.Repeat(" ", spaceLength+4), gstr.Trim(arg.Brief),
|
||||
prefix, arg.Name, gstr.Repeat(" ", spaceLength+4), brief,
|
||||
)
|
||||
)
|
||||
lineStr = gstr.WordWrap(lineStr, maxLineChars, "\n"+wordwrapPrefix)
|
||||
@ -145,11 +147,12 @@ func (c *Command) Print() {
|
||||
nameStr = fmt.Sprintf("-/--%s", arg.Name)
|
||||
}
|
||||
var (
|
||||
brief = gstr.Trim(gstr.Replace(arg.Brief, "\n", ""))
|
||||
spaceLength = maxSpaceLength - len(nameStr)
|
||||
wordwrapPrefix = gstr.Repeat(" ", len(prefix+nameStr)+spaceLength+4)
|
||||
lineStr = fmt.Sprintf(
|
||||
"%s%s%s%s\n",
|
||||
prefix, nameStr, gstr.Repeat(" ", spaceLength+4), gstr.Trim(arg.Brief),
|
||||
prefix, nameStr, gstr.Repeat(" ", spaceLength+4), brief,
|
||||
)
|
||||
)
|
||||
lineStr = gstr.WordWrap(lineStr, maxLineChars, "\n"+wordwrapPrefix)
|
||||
|
||||
@ -86,15 +86,21 @@ PLATFORMS
|
||||
plan9 386
|
||||
plan9 amd64
|
||||
solaris amd64
|
||||
`
|
||||
commandBuildBriefPack = `
|
||||
destination file path for packed file. if extension of the filename is ".go" and "-n" option is given,
|
||||
it enables packing SRC to go file, or else it packs SRC into a binary file.
|
||||
|
||||
`
|
||||
)
|
||||
|
||||
func init() {
|
||||
gtag.Sets(map[string]string{
|
||||
`commandBuildBrief`: commandBuildBrief,
|
||||
`commandBuildDc`: commandBuildDc,
|
||||
`commandBuildEg`: commandBuildEg,
|
||||
`commandBuildAd`: commandBuildAd,
|
||||
`commandBuildBrief`: commandBuildBrief,
|
||||
`commandBuildDc`: commandBuildDc,
|
||||
`commandBuildEg`: commandBuildEg,
|
||||
`commandBuildAd`: commandBuildAd,
|
||||
`commandBuildBriefPack`: commandBuildBriefPack,
|
||||
})
|
||||
}
|
||||
|
||||
@ -109,7 +115,7 @@ type commandBuildInput struct {
|
||||
Extra string `short:"e" name:"extra" brief:"extra custom \"go build\" options"`
|
||||
Mod string `short:"m" name:"mod" brief:"like \"-mod\" option of \"go build\", use \"-m none\" to disable go module"`
|
||||
Cgo bool `short:"c" name:"cgo" brief:"enable or disable cgo feature, it's disabled in default" orphan:"true"`
|
||||
Pack string `name:"pack" brief:"pack specified folder into temporary go file before building and removes it after built"`
|
||||
Pack string `name:"pack" brief:"{commandBuildBriefPack}"`
|
||||
}
|
||||
type commandBuildOutput struct{}
|
||||
|
||||
|
||||
@ -77,6 +77,11 @@ func ScanDirFile(path string, pattern string, recursive ...bool) []*File {
|
||||
return defaultResource.ScanDirFile(path, pattern, recursive...)
|
||||
}
|
||||
|
||||
// Export exports and saves specified path `src` and all its sub files to specified system path `dst` recursively.
|
||||
func Export(src, dst string) error {
|
||||
return defaultResource.Export(src, dst)
|
||||
}
|
||||
|
||||
// Dump prints the files of the default resource object.
|
||||
func Dump() {
|
||||
defaultResource.Dump()
|
||||
|
||||
@ -224,12 +224,38 @@ func (r *Resource) doScanDir(path string, pattern string, recursive bool, onlyFi
|
||||
return files
|
||||
}
|
||||
|
||||
// Export exports and saves specified path `src` and all its sub files to specified system path `dst` recursively.
|
||||
func (r *Resource) Export(src, dst string) error {
|
||||
var (
|
||||
err error
|
||||
path string
|
||||
files = r.doScanDir(src, "*", true, false)
|
||||
)
|
||||
for _, file := range files {
|
||||
path = gfile.Join(dst, file.Name())
|
||||
if file.FileInfo().IsDir() {
|
||||
err = gfile.Mkdir(path)
|
||||
} else {
|
||||
err = gfile.PutBytes(path, file.Content())
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dump prints the files of current resource object.
|
||||
func (r *Resource) Dump() {
|
||||
var info os.FileInfo
|
||||
r.tree.Iterator(func(key, value interface{}) bool {
|
||||
info = value.(*File).FileInfo()
|
||||
fmt.Printf("%v %7s %s\n", gtime.New(info.ModTime()).ISO8601(), gfile.FormatSize(info.Size()), key)
|
||||
fmt.Printf(
|
||||
"%v %7s %s\n",
|
||||
gtime.New(info.ModTime()).ISO8601(),
|
||||
gfile.FormatSize(info.Size()),
|
||||
key,
|
||||
)
|
||||
return true
|
||||
})
|
||||
fmt.Printf("TOTAL FILES: %d\n", r.tree.Size())
|
||||
|
||||
@ -7,11 +7,11 @@
|
||||
package gres_test
|
||||
|
||||
import (
|
||||
_ "github.com/gogf/gf/v2/os/gres/testdata/data"
|
||||
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
_ "github.com/gogf/gf/v2/os/gres/testdata/data"
|
||||
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
@ -231,3 +231,22 @@ func Test_ScanDirFile(t *testing.T) {
|
||||
t.Assert(files[0].Content(), "sub-test2 content")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Export(t *testing.T) {
|
||||
gres.Dump()
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
src = `template`
|
||||
dst = gfile.TempDir(gtime.TimestampNanoStr())
|
||||
err = gres.Export(src, dst)
|
||||
)
|
||||
defer gfile.Remove(dst)
|
||||
t.AssertNil(err)
|
||||
files, err := gfile.ScanDir(dst, "*", true)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(files), 14)
|
||||
|
||||
name := `template/index.html`
|
||||
t.Assert(gfile.GetContents(gfile.Join(dst, name)), gres.GetContent(name))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user