From ed9f8cd0d9a863e377dc295a918e62baa17a8245 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Thu, 17 Nov 2022 10:35:00 +0100 Subject: [PATCH] cmd/completion: Style fixes https://github.com/containers/toolbox/pull/1165 --- src/cmd/completion.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/cmd/completion.go b/src/cmd/completion.go index 6168029..1e1d007 100644 --- a/src/cmd/completion.go +++ b/src/cmd/completion.go @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Red Hat Inc. + * Copyright © 2021 – 2022 Red Hat Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,26 +29,31 @@ var completionCmd = &cobra.Command{ Short: "Generate completion script", Hidden: true, DisableFlagsInUseLine: true, - ValidArgs: []string{"bash", "zsh", "fish"}, + ValidArgs: []string{"bash", "fish", "zsh"}, Args: cobra.ExactValidArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - switch args[0] { - case "bash": - return cmd.Root().GenBashCompletionV2(os.Stdout, true) - case "zsh": - return cmd.Root().GenZshCompletion(os.Stdout) - case "fish": - return cmd.Root().GenFishCompletion(os.Stdout, true) - } - - panic("code should not be reached") - }, + RunE: completion, } func init() { rootCmd.AddCommand(completionCmd) } +func completion(cmd *cobra.Command, args []string) error { + switch args[0] { + case "bash": + err := cmd.Root().GenBashCompletionV2(os.Stdout, true) + return err + case "fish": + err := cmd.Root().GenFishCompletion(os.Stdout, true) + return err + case "zsh": + err := cmd.Root().GenZshCompletion(os.Stdout) + return err + } + + panic("code should not be reached") +} + func completionEmpty(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { return nil, cobra.ShellCompDirectiveNoFileComp }