working commit
This commit is contained in:
+50
-12
@@ -88,6 +88,8 @@ func (util *FileUtil) CreateFileCmds() *cobra.Command {
|
||||
Run: util.ListFiles,
|
||||
}
|
||||
listFilesCmd.Flags().BoolVarP(&util.listFilesParams.Detail, "detail", "D", false, "Show detail file information")
|
||||
listFilesCmd.Flags().BoolVarP(&util.listFilesParams.AsPrefix, "asprefix", "P", true, "Use path as collection path prefix")
|
||||
listFilesCmd.Flags().BoolVarP(&util.listFilesParams.AsRegexp, "asregex", "R", false, "Use path as collection path prefix")
|
||||
subCmd.AddCommand(listFilesCmd)
|
||||
|
||||
// ImportFiles
|
||||
@@ -123,6 +125,7 @@ func (util *FileUtil) CreateCollectionCmds() *cobra.Command {
|
||||
Short: "List collections in storage",
|
||||
Run: util.ListCollections,
|
||||
}
|
||||
listCollectionsCmd.Flags().BoolVarP(&util.listCollectionsParams.AsPrefix, "asprefix", "P", true, "Use path as collection path prefix")
|
||||
subCmd.AddCommand(listCollectionsCmd)
|
||||
|
||||
// DeleteCollection
|
||||
@@ -134,6 +137,7 @@ func (util *FileUtil) CreateCollectionCmds() *cobra.Command {
|
||||
}
|
||||
deleteCollectionCmd.Flags().BoolVarP(&util.deleteCollectionParams.Detail, "detail", "D", false, "Show detail file information")
|
||||
deleteCollectionCmd.Flags().BoolVarP(&util.deleteCollectionParams.AsPrefix, "asprefix", "P", false, "Use path as collection path prefix")
|
||||
deleteCollectionCmd.Flags().BoolVarP(&util.deleteCollectionParams.AsRegexp, "asregex", "R", false, "Use path as collection path prefix")
|
||||
deleteCollectionCmd.Flags().BoolVarP(&util.deleteCollectionParams.DryRun, "dryrun", "Y", false, "Simulate process, don't delete files")
|
||||
|
||||
subCmd.AddCommand(deleteCollectionCmd)
|
||||
@@ -287,6 +291,8 @@ func (util *FileUtil) deleteFile(common *CommonFileParams, params *DeleteFilePar
|
||||
type ListFilesParams struct {
|
||||
Filepath string
|
||||
Detail bool
|
||||
AsPrefix bool
|
||||
AsRegexp bool
|
||||
}
|
||||
|
||||
type ListFilesResult struct {
|
||||
@@ -306,9 +312,21 @@ func (util *FileUtil) listFiles(common *CommonFileParams, params *ListFilesParam
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if params.AsRegexp {
|
||||
params.AsPrefix = false
|
||||
}
|
||||
var pathAs terms.PathUsage
|
||||
switch {
|
||||
case params.AsRegexp:
|
||||
pathAs = terms.AsRegexp
|
||||
case params.AsPrefix:
|
||||
pathAs = terms.AsPrefix
|
||||
default:
|
||||
pathAs = terms.AsFinePath
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
files, err := client.NewClient().ListFiles(ctx, params.Filepath)
|
||||
files, err := client.NewClient().ListFiles(ctx, params.Filepath, pathAs)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -316,10 +334,7 @@ func (util *FileUtil) listFiles(common *CommonFileParams, params *ListFilesParam
|
||||
if params.Detail {
|
||||
res.Files = files
|
||||
} else {
|
||||
for _, file := range files {
|
||||
filename := filepath.Join("/", file.Collection, file.Name)
|
||||
res.Filenames = append(res.Filenames, filename)
|
||||
}
|
||||
res.Filenames = makeFilelistFromFiles(files)
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
@@ -398,7 +413,9 @@ func (util *FileUtil) importFiles(common *CommonFileParams, params *ImportFilesP
|
||||
|
||||
// ListCollections
|
||||
type ListCollectionsParams struct {
|
||||
Path string
|
||||
Path string
|
||||
AsPrefix bool
|
||||
AsRegexp bool
|
||||
}
|
||||
|
||||
type ListCollectionsResult struct {
|
||||
@@ -410,6 +427,7 @@ func (util *FileUtil) ListCollections(cmd *cobra.Command, args []string) {
|
||||
res, err := util.listCollections(&util.commonFileParams, &util.listCollectionsParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *FileUtil) listCollections(common *CommonFileParams, params *ListCollectionsParams) (*ListCollectionsResult, error) {
|
||||
var err error
|
||||
res := &ListCollectionsResult{
|
||||
@@ -419,9 +437,21 @@ func (util *FileUtil) listCollections(common *CommonFileParams, params *ListColl
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if params.AsRegexp {
|
||||
params.AsPrefix = false
|
||||
}
|
||||
var pathAs terms.PathUsage
|
||||
switch {
|
||||
case params.AsRegexp:
|
||||
pathAs = terms.AsRegexp
|
||||
case params.AsPrefix:
|
||||
pathAs = terms.AsPrefix
|
||||
default:
|
||||
pathAs = terms.AsFinePath
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
collecions, err := client.NewClient().ListCollections(ctx, params.Path)
|
||||
collecions, err := client.NewClient().ListCollections(ctx, params.Path, pathAs)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -434,6 +464,7 @@ type DeleteCollectionParams struct {
|
||||
Path string
|
||||
Detail bool
|
||||
AsPrefix bool
|
||||
AsRegexp bool
|
||||
DryRun bool
|
||||
}
|
||||
|
||||
@@ -447,6 +478,7 @@ func (util *FileUtil) DeleteCollection(cmd *cobra.Command, args []string) {
|
||||
res, err := util.deleteCollection(&util.commonFileParams, &util.deleteCollectionParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *FileUtil) deleteCollection(common *CommonFileParams, params *DeleteCollectionParams) (*DeleteCollectionResult, error) {
|
||||
var err error
|
||||
res := &DeleteCollectionResult{
|
||||
@@ -458,7 +490,7 @@ func (util *FileUtil) deleteCollection(common *CommonFileParams, params *DeleteC
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
var pathAs terms.PathAs
|
||||
var pathAs terms.PathUsage
|
||||
switch {
|
||||
case params.AsPrefix:
|
||||
pathAs = terms.AsPrefix
|
||||
@@ -472,10 +504,16 @@ func (util *FileUtil) deleteCollection(common *CommonFileParams, params *DeleteC
|
||||
if params.Detail {
|
||||
res.Files = files
|
||||
} else {
|
||||
for _, file := range files {
|
||||
res.Filenames = append(res.Filenames, filepath.Join(file.Collection, file.Name))
|
||||
}
|
||||
slices.Sort(res.Filenames)
|
||||
res.Filenames = makeFilelistFromFiles(files)
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func makeFilelistFromFiles(files []descr.File) []string {
|
||||
res := make([]string, 0, len(files))
|
||||
for _, file := range files {
|
||||
res = append(res, filepath.Join(file.Collection, file.Name))
|
||||
}
|
||||
slices.Sort(res)
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user