Bladeren bron

Volume command is only available in aci context type, with ACI specific flags

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif 5 jaren geleden
bovenliggende
commit
38a8f5310b
4 gewijzigde bestanden met toevoegingen van 18 en 13 verwijderingen
  1. 0 0
      cli/cmd/volume/acilist.go
  2. 0 0
      cli/cmd/volume/acilist_test.go
  3. 13 12
      cli/cmd/volume/acivolume.go
  4. 5 1
      cli/main.go

+ 0 - 0
cli/cmd/volume/list.go → cli/cmd/volume/acilist.go


+ 0 - 0
cli/cmd/volume/list_test.go → cli/cmd/volume/acilist_test.go


+ 13 - 12
cli/cmd/volume/volume.go → cli/cmd/volume/acivolume.go

@@ -20,14 +20,15 @@ import (
 	"context"
 	"context"
 	"fmt"
 	"fmt"
 
 
+	"github.com/spf13/cobra"
+
 	"github.com/docker/compose-cli/aci"
 	"github.com/docker/compose-cli/aci"
 	"github.com/docker/compose-cli/api/client"
 	"github.com/docker/compose-cli/api/client"
 	"github.com/docker/compose-cli/progress"
 	"github.com/docker/compose-cli/progress"
-	"github.com/spf13/cobra"
 )
 )
 
 
-// Command manage volumes
-func Command() *cobra.Command {
+// ACICommand manage volumes
+func ACICommand() *cobra.Command {
 	cmd := &cobra.Command{
 	cmd := &cobra.Command{
 		Use:   "volume",
 		Use:   "volume",
 		Short: "Manages volumes",
 		Short: "Manages volumes",
@@ -42,7 +43,7 @@ func Command() *cobra.Command {
 }
 }
 
 
 func createVolume() *cobra.Command {
 func createVolume() *cobra.Command {
-	opts := aci.VolumeCreateOptions{}
+	aciOpts := aci.VolumeCreateOptions{}
 	cmd := &cobra.Command{
 	cmd := &cobra.Command{
 		Use:   "create",
 		Use:   "create",
 		Short: "Creates an Azure file share to use as ACI volume.",
 		Short: "Creates an Azure file share to use as ACI volume.",
@@ -54,7 +55,7 @@ func createVolume() *cobra.Command {
 				return err
 				return err
 			}
 			}
 			err = progress.Run(ctx, func(ctx context.Context) error {
 			err = progress.Run(ctx, func(ctx context.Context) error {
-				_, err := c.VolumeService().Create(ctx, opts)
+				_, err := c.VolumeService().Create(ctx, aciOpts)
 				if err != nil {
 				if err != nil {
 					return err
 					return err
 				}
 				}
@@ -68,13 +69,13 @@ func createVolume() *cobra.Command {
 		},
 		},
 	}
 	}
 
 
-	cmd.Flags().StringVar(&opts.Account, "storage-account", "", "Storage account name")
-	cmd.Flags().StringVar(&opts.Fileshare, "fileshare", "", "Fileshare name")
+	cmd.Flags().StringVar(&aciOpts.Account, "storage-account", "", "Storage account name")
+	cmd.Flags().StringVar(&aciOpts.Fileshare, "fileshare", "", "Fileshare name")
 	return cmd
 	return cmd
 }
 }
 
 
 func rmVolume() *cobra.Command {
 func rmVolume() *cobra.Command {
-	opts := aci.VolumeDeleteOptions{}
+	aciOpts := aci.VolumeDeleteOptions{}
 	cmd := &cobra.Command{
 	cmd := &cobra.Command{
 		Use:   "rm",
 		Use:   "rm",
 		Short: "Deletes an Azure file share and/or the Azure storage account.",
 		Short: "Deletes an Azure file share and/or the Azure storage account.",
@@ -84,12 +85,12 @@ func rmVolume() *cobra.Command {
 			if err != nil {
 			if err != nil {
 				return err
 				return err
 			}
 			}
-			return c.VolumeService().Delete(cmd.Context(), opts)
+			return c.VolumeService().Delete(cmd.Context(), aciOpts)
 		},
 		},
 	}
 	}
 
 
-	cmd.Flags().StringVar(&opts.Account, "storage-account", "", "Storage account name")
-	cmd.Flags().StringVar(&opts.Fileshare, "fileshare", "", "Fileshare name")
-	cmd.Flags().BoolVar(&opts.DeleteAccount, "delete-storage-account", false, "Also delete storage account")
+	cmd.Flags().StringVar(&aciOpts.Account, "storage-account", "", "Storage account name")
+	cmd.Flags().StringVar(&aciOpts.Fileshare, "fileshare", "", "Fileshare name")
+	cmd.Flags().BoolVar(&aciOpts.DeleteAccount, "delete-storage-account", false, "Also delete storage account")
 	return cmd
 	return cmd
 }
 }

+ 5 - 1
cli/main.go

@@ -135,7 +135,6 @@ func main() {
 
 
 		// Place holders
 		// Place holders
 		cmd.EcsCommand(),
 		cmd.EcsCommand(),
-		volume.Command(),
 	)
 	)
 
 
 	helpFunc := root.HelpFunc()
 	helpFunc := root.HelpFunc()
@@ -185,6 +184,11 @@ func main() {
 		ctype = cc.Type()
 		ctype = cc.Type()
 	}
 	}
 
 
+	if ctype == store.AciContextType {
+		// we can also pass ctype as a parameter to the volume command and customize subcommands, flags, etc. when we have other backend implementations
+		root.AddCommand(volume.ACICommand())
+	}
+
 	metrics.Track(ctype, os.Args[1:], root.PersistentFlags())
 	metrics.Track(ctype, os.Args[1:], root.PersistentFlags())
 
 
 	ctx = apicontext.WithCurrentContext(ctx, currentContext)
 	ctx = apicontext.WithCurrentContext(ctx, currentContext)