Files
faas-cli/commands/bash_completion.go
Tommy Stigen Olsen 7cfceb68b0 Move error printing out of each subcommand
Instead of having fmt.Println(err) like statements scattered
around the each individual function, the error message returned
by each sub command will now be printed on screen.

Signed-off-by: Tommy Stigen Olsen <tommysolsen@gmail.com>
2017-11-14 19:26:19 +00:00

41 lines
1.0 KiB
Go

// Copyright (c) Alex Ellis 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package commands
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
faasCmd.AddCommand(bashcompletionCmd)
}
// bashcompletionCmd generates a bash completion file
// TODO split into `completion bash`/`completion zsh`?
var bashcompletionCmd = &cobra.Command{
Use: "bashcompletion FILENAME",
Short: "Generate a bash completion file",
Long: `Generate a bash completion file for the client.
This currently only works on Bash version 4, and is hidden
pending a merge of https://github.com/spf13/cobra/pull/520.`,
Hidden: true,
RunE: runBashcompletion,
}
func runBashcompletion(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("please provide filename for bash completion")
}
fileName := args[0]
err := faasCmd.GenBashCompletionFile(fileName)
if err != nil {
return fmt.Errorf("unable to create bash completion file")
}
return nil
}