From 0160c9fc6bf543b4f5ba098e62f507ef6d0ce357 Mon Sep 17 00:00:00 2001 From: Ramiro Algozino Date: Thu, 11 Apr 2024 18:51:41 +0200 Subject: [PATCH] fix(cli/server): serve command expected positional args (#2382) fix(cli/server): serve command expected positinal args Expect exactly one positional argument for the serve command with the path to the config file. Signed-off-by: Ramiro Algozino --- pkg/cli/server/root.go | 1 + pkg/cli/server/root_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/cli/server/root.go b/pkg/cli/server/root.go index 2ce6fa69c..4916cd200 100644 --- a/pkg/cli/server/root.go +++ b/pkg/cli/server/root.go @@ -47,6 +47,7 @@ func newServeCmd(conf *config.Config) *cobra.Command { Aliases: []string{"serve"}, Short: "`serve` stores and distributes OCI images", Long: "`serve` stores and distributes OCI images", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if len(args) > 0 { if err := LoadConfiguration(conf, args[0]); err != nil { diff --git a/pkg/cli/server/root_test.go b/pkg/cli/server/root_test.go index 38c08c3c4..b0f7e94f7 100644 --- a/pkg/cli/server/root_test.go +++ b/pkg/cli/server/root_test.go @@ -48,6 +48,18 @@ func TestServe(t *testing.T) { }) Convey("Test serve config", t, func(c C) { + Convey("no config arg", func(c C) { + os.Args = []string{"cli_test", "serve"} + err := cli.NewServerRootCmd().Execute() + So(err, ShouldNotBeNil) + }) + + Convey("two args", func(c C) { + os.Args = []string{"cli_test", "serve", "config", "second arg"} + err := cli.NewServerRootCmd().Execute() + So(err, ShouldNotBeNil) + }) + Convey("unknown config", func(c C) { os.Args = []string{"cli_test", "serve", path.Join(os.TempDir(), "/x")} err := cli.NewServerRootCmd().Execute()