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 <ramiro@sighup.io>
This commit is contained in:
Ramiro Algozino
2024-04-11 18:51:41 +02:00
committed by GitHub
parent 6b3c160176
commit 0160c9fc6b
2 changed files with 13 additions and 0 deletions
+1
View File
@@ -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 {
+12
View File
@@ -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()