Skip to content

Commit

Permalink
Merge pull request #12 from shiftky/add_exec_sub_cmd
Browse files Browse the repository at this point in the history
Add 'exec' sub-command to tmsh-cli
  • Loading branch information
Yuki KIRII authored Oct 23, 2017
2 parents 8736c5d + 68a7db5 commit bfb6ca2
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions cmd/tmsh/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -16,9 +17,31 @@ var RootCmd = &cobra.Command{

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of tmsh command.",
Short: "Print the version number of tmsh-cli command.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("tmsh v0.1.0")
fmt.Println("tmsh v0.2.0")
},
}

var execCmd = &cobra.Command{
Use: "exec [tmsh command]",
Short: "Execute any command of TMSH",
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
cmd.Usage()
os.Exit(2)
}

bigip := NewSession()
defer bigip.Close()

ret, err := bigip.ExecuteCommand(args[0])
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

fmt.Println(ret)
},
}

Expand All @@ -38,4 +61,5 @@ func init() {
viper.BindPFlag("TMSH_PORT", RootCmdFlags.Lookup("port"))

RootCmd.AddCommand(versionCmd)
RootCmd.AddCommand(execCmd)
}

0 comments on commit bfb6ca2

Please sign in to comment.