From 38a8f5310b64574cb980de2b2a6a94659239c62e Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Wed, 9 Sep 2020 10:46:11 +0200 Subject: [PATCH] Volume command is only available in aci context type, with ACI specific flags Signed-off-by: Guillaume Tardif --- cli/cmd/volume/{list.go => acilist.go} | 0 .../volume/{list_test.go => acilist_test.go} | 0 cli/cmd/volume/{volume.go => acivolume.go} | 25 ++++++++++--------- cli/main.go | 6 ++++- 4 files changed, 18 insertions(+), 13 deletions(-) rename cli/cmd/volume/{list.go => acilist.go} (100%) rename cli/cmd/volume/{list_test.go => acilist_test.go} (100%) rename cli/cmd/volume/{volume.go => acivolume.go} (72%) diff --git a/cli/cmd/volume/list.go b/cli/cmd/volume/acilist.go similarity index 100% rename from cli/cmd/volume/list.go rename to cli/cmd/volume/acilist.go diff --git a/cli/cmd/volume/list_test.go b/cli/cmd/volume/acilist_test.go similarity index 100% rename from cli/cmd/volume/list_test.go rename to cli/cmd/volume/acilist_test.go diff --git a/cli/cmd/volume/volume.go b/cli/cmd/volume/acivolume.go similarity index 72% rename from cli/cmd/volume/volume.go rename to cli/cmd/volume/acivolume.go index 1f9b4b956..de6c0a46b 100644 --- a/cli/cmd/volume/volume.go +++ b/cli/cmd/volume/acivolume.go @@ -20,14 +20,15 @@ import ( "context" "fmt" + "github.com/spf13/cobra" + "github.com/docker/compose-cli/aci" "github.com/docker/compose-cli/api/client" "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{ Use: "volume", Short: "Manages volumes", @@ -42,7 +43,7 @@ func Command() *cobra.Command { } func createVolume() *cobra.Command { - opts := aci.VolumeCreateOptions{} + aciOpts := aci.VolumeCreateOptions{} cmd := &cobra.Command{ Use: "create", Short: "Creates an Azure file share to use as ACI volume.", @@ -54,7 +55,7 @@ func createVolume() *cobra.Command { return err } err = progress.Run(ctx, func(ctx context.Context) error { - _, err := c.VolumeService().Create(ctx, opts) + _, err := c.VolumeService().Create(ctx, aciOpts) if err != nil { 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 } func rmVolume() *cobra.Command { - opts := aci.VolumeDeleteOptions{} + aciOpts := aci.VolumeDeleteOptions{} cmd := &cobra.Command{ Use: "rm", Short: "Deletes an Azure file share and/or the Azure storage account.", @@ -84,12 +85,12 @@ func rmVolume() *cobra.Command { if err != nil { 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 } diff --git a/cli/main.go b/cli/main.go index 69d84324d..db88150eb 100644 --- a/cli/main.go +++ b/cli/main.go @@ -135,7 +135,6 @@ func main() { // Place holders cmd.EcsCommand(), - volume.Command(), ) helpFunc := root.HelpFunc() @@ -185,6 +184,11 @@ func main() { 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()) ctx = apicontext.WithCurrentContext(ctx, currentContext)