each command use its own options to avoid parameter collision

fix https://github.com/chrislusf/seaweedfs/issues/152
This commit is contained in:
chrislusf
2015-06-01 19:25:01 -07:00
parent e09f45f5ed
commit 51aac49e82
3 changed files with 63 additions and 45 deletions

View File

@@ -15,15 +15,21 @@ import (
"github.com/chrislusf/seaweedfs/go/storage"
)
func init() {
cmdExport.Run = runExport // break init cycle
}
const (
defaultFnFormat = `{{.Mime}}/{{.Id}}:{{.Name}}`
timeFormat = "2006-01-02T15:04:05"
)
var (
export ExportOptions
)
type ExportOptions struct {
dir *string
collection *string
volumeId *int
}
var cmdExport = &Command{
UsageLine: "export -dir=/tmp -volumeId=234 -o=/dir/name.tar -fileNameFormat={{.Name}} -newer='" + timeFormat + "'",
Short: "list or export files from one volume data file",
@@ -34,13 +40,17 @@ var cmdExport = &Command{
`,
}
func init() {
cmdExport.Run = runExport // break init cycle
export.dir = cmdExport.Flag.String("dir", ".", "input data directory to store volume data files")
export.collection = cmdExport.Flag.String("collection", "", "the volume collection name")
export.volumeId = cmdExport.Flag.Int("volumeId", -1, "a volume id. The volume .dat and .idx files should already exist in the dir.")
dest = cmdExport.Flag.String("o", "", "output tar file name, must ends with .tar, or just a \"-\" for stdout")
format = cmdExport.Flag.String("fileNameFormat", defaultFnFormat, "filename format, default to {{.Mime}}/{{.Id}}:{{.Name}}")
newer = cmdExport.Flag.String("newer", "", "export only files newer than this time, default is all files. Must be specified in RFC3339 without timezone")
}
var (
exportVolumePath = cmdExport.Flag.String("dir", ".", "input data directory to store volume data files")
exportCollection = cmdExport.Flag.String("collection", "", "the volume collection name")
exportVolumeId = cmdExport.Flag.Int("volumeId", -1, "a volume id. The volume .dat and .idx files should already exist in the dir.")
dest = cmdExport.Flag.String("o", "", "output tar file name, must ends with .tar, or just a \"-\" for stdout")
format = cmdExport.Flag.String("fileNameFormat", defaultFnFormat, "filename format, default to {{.Mime}}/{{.Id}}:{{.Name}}")
newer = cmdExport.Flag.String("newer", "", "export only files newer than this time, default is all files. Must be specified in RFC3339 without timezone")
tarFh *tar.Writer
tarHeader tar.Header
fnTmpl *template.Template