Skip to content

Commit

Permalink
CLI: when 'ls bucket/objname' becomes 'ls bucket --prefix objname'
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Sep 24, 2024
1 parent c959339 commit e3febd2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
5 changes: 3 additions & 2 deletions api/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/debug"
jsoniter "github.com/json-iterator/go"
)

Expand Down Expand Up @@ -92,7 +91,9 @@ func hdr2msg(bck cmn.Bck, status int, err error) error {
if !ok {
return err
}
debug.Assert(herr.Status == status, herr.Status, " vs ", status)
if status == 0 && herr.Status != 0 { // (connection refused)
return err
}

quoted := "\"" + bck.Cname("") + "\""
if !bck.IsQuery() && status == http.StatusNotFound {
Expand Down
5 changes: 4 additions & 1 deletion cmd/cli/cli/bucket_hdlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,15 @@ func listAnyHandler(c *cli.Context) error {
if _, err := headBucket(bck, true /* don't add */); err != nil {
return err
}
err := showObjProps(c, bck, objName)
notfound, err := showObjProps(c, bck, objName)
if err == nil {
if _, errV := archive.Mime("", objName); errV == nil {
fmt.Fprintf(c.App.Writer, "\n('ais ls %s %s' to list archived contents, %s for details)\n",
bck.Cname(objName), flprn(listArchFlag), qflprn(cli.HelpFlag))
}
} else if notfound {
prefix := objName
err = listObjects(c, bck, prefix, false)
}
return err
case bck.Name == "" || flagIsSet(c, bckSummaryFlag): // list or summarize bucket(s)
Expand Down
15 changes: 8 additions & 7 deletions cmd/cli/cli/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func calcPutRefresh(c *cli.Context) time.Duration {
}

// via `ais ls bucket/object` and `ais show bucket/object`
func showObjProps(c *cli.Context, bck cmn.Bck, objName string) error {
func showObjProps(c *cli.Context, bck cmn.Bck, objName string) (notfound bool, _ error) {
var (
propsFlag []string
selectedProps []string
Expand All @@ -263,15 +263,16 @@ func showObjProps(c *cli.Context, bck cmn.Bck, objName string) error {
units, errU = parseUnitsFlag(c, unitsFlag)
)
if errU != nil {
return errU
return false, errU
}
if flagIsSet(c, objNotCachedPropsFlag) || flagIsSet(c, allObjsOrBcksFlag) {
hargs.FltPresence = apc.FltExists
}
objProps, err := api.HeadObject(apiBP, bck, objName, hargs)
if err != nil {
if !cmn.IsStatusNotFound(err) {
return err
notfound = cmn.IsStatusNotFound(err)
if !notfound {
return notfound, err
}
var hint string
if apc.IsFltPresent(hargs.FltPresence) && bck.IsRemote() {
Expand All @@ -281,7 +282,7 @@ func showObjProps(c *cli.Context, bck cmn.Bck, objName string) error {
hint = fmt.Sprintf(" (tip: try %s option)", qflprn(objNotCachedPropsFlag))
}
}
return fmt.Errorf("%q not found in %s%s", objName, bck.Cname(""), hint)
return notfound, fmt.Errorf("%q not found in %s%s", objName, bck.Cname(""), hint)
}

if flagIsSet(c, allPropsFlag) {
Expand Down Expand Up @@ -329,9 +330,9 @@ func showObjProps(c *cli.Context, bck cmn.Bck, objName string) error {
})

if flagIsSet(c, noHeaderFlag) {
return teb.Print(propNVs, teb.PropValTmplNoHdr)
return false, teb.Print(propNVs, teb.PropValTmplNoHdr)
}
return teb.Print(propNVs, teb.PropValTmpl)
return false, teb.Print(propNVs, teb.PropValTmpl)
}

func propVal(op *cmn.ObjectProps, name string) (v string) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/cli/show_hdlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ func showObjectHandler(c *cli.Context) error {
if _, err := headBucket(bck, true /* don't add */); err != nil {
return err
}
return showObjProps(c, bck, object)
_, err = showObjProps(c, bck, object)
return err
}

func showBckPropsHandler(c *cli.Context) error {
Expand Down

0 comments on commit e3febd2

Please sign in to comment.