cli: add config and images command

Extends the existing zot CLI to add commands for listing all images and
their details on a zot server.
Listing all images introduces the need for configurations.

Each configuration has a name and URL at the least. Check 'zot config
-h' for more details.

The user can specify the URL of zot server explicitly while running the
command or configure a URL and pass it directly.

Adding a configuration:
zot config add aci-zot <zot-url>

Run 'zot config --help' for more.

Listing all images:
zot images --url <zot-url>

Pass a config instead of the url:
zot images <config-name>

Filter the list of images by image name:
zot images <config-name> --name <image-name>

Run 'zot images --help' for all details

- Stores configurations in '$HOME/.zot' file

Add CLI README
This commit is contained in:
Tanmay Naik
2020-06-16 21:52:40 -04:00
parent 4a1519bb1d
commit ad684ac44b
17 changed files with 2169 additions and 84 deletions
+10 -9
View File
@@ -3,6 +3,7 @@ package cli_test
import (
"io/ioutil"
"os"
"path"
"testing"
"github.com/anuvu/zot/pkg/cli"
@@ -16,13 +17,13 @@ func TestUsage(t *testing.T) {
Convey("Test usage", t, func(c C) {
os.Args = []string{"cli_test", "help"}
err := cli.NewRootCmd().Execute()
err := cli.NewRootCmd(os.TempDir()).Execute()
So(err, ShouldBeNil)
})
Convey("Test version", t, func(c C) {
os.Args = []string{"cli_test", "--version"}
err := cli.NewRootCmd().Execute()
err := cli.NewRootCmd(os.TempDir()).Execute()
So(err, ShouldBeNil)
})
}
@@ -34,19 +35,19 @@ func TestServe(t *testing.T) {
Convey("Test serve help", t, func(c C) {
os.Args = []string{"cli_test", "serve", "-h"}
err := cli.NewRootCmd().Execute()
err := cli.NewRootCmd(os.TempDir()).Execute()
So(err, ShouldBeNil)
})
Convey("Test serve config", t, func(c C) {
Convey("unknown config", func(c C) {
os.Args = []string{"cli_test", "serve", "/tmp/x"}
So(func() { _ = cli.NewRootCmd().Execute() }, ShouldPanic)
os.Args = []string{"cli_test", "serve", path.Join(os.TempDir(), "/x")}
So(func() { _ = cli.NewRootCmd(os.TempDir()).Execute() }, ShouldPanic)
})
Convey("non-existent config", func(c C) {
os.Args = []string{"cli_test", "serve", "/tmp/x.yaml"}
So(func() { _ = cli.NewRootCmd().Execute() }, ShouldPanic)
os.Args = []string{"cli_test", "serve", path.Join(os.TempDir(), "/x.yaml")}
So(func() { _ = cli.NewRootCmd(os.TempDir()).Execute() }, ShouldPanic)
})
Convey("bad config", func(c C) {
@@ -59,7 +60,7 @@ func TestServe(t *testing.T) {
err = tmpfile.Close()
So(err, ShouldBeNil)
os.Args = []string{"cli_test", "serve", tmpfile.Name()}
So(func() { _ = cli.NewRootCmd().Execute() }, ShouldPanic)
So(func() { _ = cli.NewRootCmd(os.TempDir()).Execute() }, ShouldPanic)
})
})
}
@@ -71,7 +72,7 @@ func TestGC(t *testing.T) {
Convey("Test gc", t, func(c C) {
os.Args = []string{"cli_test", "garbage-collect", "-h"}
err := cli.NewRootCmd().Execute()
err := cli.NewRootCmd(os.TempDir()).Execute()
So(err, ShouldBeNil)
})
}