-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from github/add-more-cmds-to-cli
Add more cmds to cli
- Loading branch information
Showing
3 changed files
with
101 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var nodesToGetHotThreads []string | ||
|
||
func init() { | ||
cmdHotThreads.Flags().StringArrayVarP(&nodesToGetHotThreads, "nodes", "n", []string{}, "Elasticsearch nodes to get hot threads for. (optional, omitted will include all nodes)") | ||
rootCmd.AddCommand(cmdHotThreads) | ||
} | ||
|
||
var cmdHotThreads = &cobra.Command{ | ||
Use: "hotthreads", | ||
Short: "Display the current hot threads by node in the cluster.", | ||
Long: `Show the current hot threads across a set of nodes within the cluster.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
v := getClient() | ||
|
||
if len(nodesToGetHotThreads) == 0 { | ||
threads, err := v.GetHotThreads() | ||
if err != nil { | ||
fmt.Printf("Error getting hot threads: %s\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Println(threads) | ||
return | ||
} | ||
|
||
threads, err := v.GetNodesHotThreads(nodesToGetHotThreads) | ||
if err != nil { | ||
fmt.Printf("Error getting mappings: %s\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Println(threads) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var indexToGetMappings string | ||
|
||
func init() { | ||
cmdIndexMappings.Flags().StringVarP(&indexToGetMappings, "index", "i", "", "Elasticsearch index to retrieve mappings from (required)") | ||
err := cmdIndexMappings.MarkFlagRequired("index") | ||
if err != nil { | ||
fmt.Printf("Error binding name configuration flag: %s \n", err) | ||
os.Exit(1) | ||
} | ||
rootCmd.AddCommand(cmdIndexMappings) | ||
} | ||
|
||
var cmdIndexMappings = &cobra.Command{ | ||
Use: "mappings", | ||
Short: "Display the mappings of the specified index.", | ||
Long: `Show the mappings of the specified index within the cluster.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
v := getClient() | ||
|
||
mappings, err := v.GetPrettyIndexMappings(indexToGetMappings) | ||
|
||
if err != nil { | ||
fmt.Printf("Error getting mappings: %s\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Println(mappings) | ||
}, | ||
} |