Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/goal/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func init() {
// ledger.go
rootCmd.AddCommand(ledgerCmd)

// completion.go
rootCmd.AddCommand(completionCmd)

// Config
defaultDataDirValue := []string{""}
rootCmd.PersistentFlags().StringArrayVarP(&dataDirs, "datadir", "d", defaultDataDirValue, "Data directory for the node")
Expand Down
59 changes: 59 additions & 0 deletions cmd/goal/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (C) 2019 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package main

import (
"os"

"github.com/spf13/cobra"
)

func init() {
completionCmd.AddCommand(bashCompletionCmd)
completionCmd.AddCommand(zshCompletionCmd)
}

var completionCmd = &cobra.Command{
Use: "completion",
Short: "Shell completion helper",
Long: "Shell completion helper",
Args: validateNoPosArgsFn,
Run: func(cmd *cobra.Command, args []string) {
// If no arguments passed, we should fallback to help
cmd.HelpFunc()(cmd, args)
},
}

var bashCompletionCmd = &cobra.Command{
Use: "bash",
Short: "Generate bash completion commands",
Long: "Generate bash completion commands",
Args: validateNoPosArgsFn,
Run: func(cmd *cobra.Command, _ []string) {
rootCmd.GenBashCompletion(os.Stdout)
},
}

var zshCompletionCmd = &cobra.Command{
Use: "zsh",
Short: "Generate zsh completion commands",
Long: "Generate zsh completion commands",
Args: validateNoPosArgsFn,
Run: func(cmd *cobra.Command, _ []string) {
rootCmd.GenZshCompletion(os.Stdout)
},
}