Wrap the Store.Names() method in the CLI

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai 2017-09-13 14:54:32 -04:00
parent a546c6d7a4
commit 29a5d64633
4 changed files with 57 additions and 0 deletions

View File

@ -10,6 +10,30 @@ import (
"github.com/containers/storage/pkg/mflag"
)
func getNames(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
if len(args) < 1 {
return 1
}
id, err := m.Lookup(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return 1
}
names, err := m.Names(id)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return 1
}
if jsonOutput {
json.NewEncoder(os.Stdout).Encode(append([]string{}, names...))
} else {
for _, name := range names {
fmt.Printf("%s\n", name)
}
}
return 0
}
func addNames(flags *mflag.FlagSet, action string, m storage.Store, args []string) int {
if len(args) < 1 {
return 1
@ -71,6 +95,16 @@ func setNames(flags *mflag.FlagSet, action string, m storage.Store, args []strin
}
func init() {
commands = append(commands, command{
names: []string{"get-names", "getnames"},
optionsHelp: "[options [...]] imageOrContainerNameOrID",
usage: "Get layer, image, or container name or names",
minArgs: 1,
action: getNames,
addFlags: func(flags *mflag.FlagSet, cmd *command) {
flags.BoolVar(&jsonOutput, []string{"-json", "j"}, jsonOutput, "Prefer JSON output")
},
})
commands = append(commands, command{
names: []string{"add-names", "addnames"},
optionsHelp: "[options [...]] imageOrContainerNameOrID",

View File

@ -22,4 +22,5 @@ other layer, image, or container.
**containers-storage add-names -n my-awesome-container -n my-for-realsies-awesome-container f3be6c6134d0d980936b4c894f1613b69a62b79588fdeda744d0be3693bde8ec**
## SEE ALSO
containers-storage-get-names(1)
containers-storage-set-names(1)

View File

@ -0,0 +1,21 @@
## containers-storage-get-names 1 "September 2017"
## NAME
containers-storage get-names - Get names of a layer/image/container
## SYNOPSIS
**containers-storage** **get-names** *layerOrImageOrContainerNameOrID*
## DESCRIPTION
In addition to IDs, *layers*, *images*, and *containers* can have
human-readable names assigned to them in *containers-storage*. The *get-names*
command can be used to read the list of names for any of them.
## OPTIONS
## EXAMPLE
**containers-storage get-names f3be6c6134d0d980936b4c894f1613b69a62b79588fdeda744d0be3693bde8ec**
## SEE ALSO
containers-storage-add-names(1)
containers-storage-set-names(1)

View File

@ -25,3 +25,4 @@ will be removed from the layer, image, or container.
## SEE ALSO
containers-storage-add-names(1)
containers-storage-get-names(1)