Skip to content

Commit

Permalink
Cleanup commands
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
  • Loading branch information
ondrej-fabry committed Aug 2, 2019
1 parent f32d90a commit 412d2fb
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 239 deletions.
7 changes: 3 additions & 4 deletions cmd/agentctl/agentctl.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package main

import (
"fmt"
"os"

"github.com/ligato/vpp-agent/cmd/agentctl/cmd"
"github.com/ligato/vpp-agent/cmd/agentctl/commands"
)

func main() {
if err := cmd.RootCmd.Execute(); err != nil {
fmt.Println(err)
rootCmd := commands.NewRootCmd("agentctl")
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
54 changes: 0 additions & 54 deletions cmd/agentctl/cmd/root.go

This file was deleted.

28 changes: 13 additions & 15 deletions cmd/agentctl/cmd/del.go → cmd/agentctl/commands/del.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
package cmd
package commands

import (
"errors"
"strings"

"github.com/ligato/cn-infra/db/keyval"
"github.com/ligato/cn-infra/servicelabel"
"github.com/ligato/vpp-agent/cmd/agentctl/utils"
"github.com/spf13/cobra"

"errors"
"github.com/ligato/vpp-agent/cmd/agentctl/utils"
)

// RootCmd represents the base command when called without any subcommands.
var delConfig = &cobra.Command{
Use: "del <key>",
Aliases: []string{"d"},
Short: "Delete configuration file",
Long: `
func delCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "del <key>",
Aliases: []string{"d"},
Short: "Delete configuration file",
Long: `
Delete configuration file
`,
Args: cobra.RangeArgs(1, 1),
Run: delFunction,
}

func init() {
RootCmd.AddCommand(delConfig)
Args: cobra.RangeArgs(1, 1),
Run: delFunction,
}
return cmd
}

func delFunction(cmd *cobra.Command, args []string) {
Expand Down
98 changes: 49 additions & 49 deletions cmd/agentctl/cmd/dump.go → cmd/agentctl/commands/dump.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,70 @@
package cmd
package commands

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/ligato/vpp-agent/api/models/linux"
"github.com/ligato/vpp-agent/api/models/vpp"
"github.com/ligato/vpp-agent/cmd/agentctl/utils"

"github.com/ligato/vpp-agent/cmd/agentctl/restapi"
"github.com/ligato/vpp-agent/cmd/agentctl/utils"
"github.com/ligato/vpp-agent/plugins/restapi/resturl"
"github.com/spf13/cobra"
)

// RootCmd represents the base command when called without any subcommands.
var dumpCmd = &cobra.Command{
Use: "dump",
Aliases: []string{"d"},
Short: "Dump command for vppagent",
Long: `
A Dump tool to connect to vppagent and dump value.
Use the 'ETCD_ENDPOINTS'' environment variable or the 'endpoints'
flag in the command line to specify vppagent instances to
connect to.
`,
Example: `Specify the vppagent to connect to and run VPP CLI command:
func dumpCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "dump",
Aliases: []string{"d"},
Short: "Dump command for vppagent",
/*Long: `
A Dump tool to connect to vppagent and dump value.
Use the 'ETCD_ENDPOINTS'' environment variable or the 'endpoints'
flag in the command line to specify vppagent instances to
connect to.
`,*/
Example: `Specify the vppagent to connect to and run VPP CLI command:
$ export ETCD_ENDPOINTS=172.17.0.3:9191
$ ./agentctl dump <dump cmd>
Do as above, but with a command line flag:
$ ./agentctl --endpoints 172.17.0.3:9191 dump <dump cmd>
`,

Args: cobra.MinimumNArgs(2),
Args: cobra.MinimumNArgs(2),
}

cmd.AddCommand(dumpLinuxInterface)
cmd.AddCommand(dumpLinuxRoutes)
cmd.AddCommand(dumpLinuxArps)
cmd.AddCommand(dumpACLIP)
cmd.AddCommand(dumpACLMACIP)
cmd.AddCommand(dumpInterface)
cmd.AddCommand(dumpLoopback)
cmd.AddCommand(dumpEthernet)
cmd.AddCommand(dumpMemif)
cmd.AddCommand(dumpTap)
cmd.AddCommand(dumpAfPacket)
cmd.AddCommand(dumpVxLan)
cmd.AddCommand(dumpNatGlobal)
cmd.AddCommand(dumpNatDNat)
cmd.AddCommand(dumpBd)
cmd.AddCommand(dumpFib)
cmd.AddCommand(dumpXc)
cmd.AddCommand(dumpRoutes)
cmd.AddCommand(dumpArps)
cmd.AddCommand(dumpPArpIfs)
cmd.AddCommand(dumpPArpRngs)
cmd.AddCommand(dumpCommand)
cmd.AddCommand(dumpTelemetry)
cmd.AddCommand(dumpTMemory)
cmd.AddCommand(dumpTRuntime)
cmd.AddCommand(dumpTNodeCount)
cmd.AddCommand(dumpTracer)
cmd.AddCommand(dumpIndex)

return cmd
}

var dumpLinuxInterface = &cobra.Command{
Expand Down Expand Up @@ -315,38 +347,6 @@ var dumpIndex = &cobra.Command{
Run: indexDumpFunction,
}

func init() {
RootCmd.AddCommand(dumpCmd)
dumpCmd.AddCommand(dumpLinuxInterface)
dumpCmd.AddCommand(dumpLinuxRoutes)
dumpCmd.AddCommand(dumpLinuxArps)
dumpCmd.AddCommand(dumpACLIP)
dumpCmd.AddCommand(dumpACLMACIP)
dumpCmd.AddCommand(dumpInterface)
dumpCmd.AddCommand(dumpLoopback)
dumpCmd.AddCommand(dumpEthernet)
dumpCmd.AddCommand(dumpMemif)
dumpCmd.AddCommand(dumpTap)
dumpCmd.AddCommand(dumpAfPacket)
dumpCmd.AddCommand(dumpVxLan)
dumpCmd.AddCommand(dumpNatGlobal)
dumpCmd.AddCommand(dumpNatDNat)
dumpCmd.AddCommand(dumpBd)
dumpCmd.AddCommand(dumpFib)
dumpCmd.AddCommand(dumpXc)
dumpCmd.AddCommand(dumpRoutes)
dumpCmd.AddCommand(dumpArps)
dumpCmd.AddCommand(dumpPArpIfs)
dumpCmd.AddCommand(dumpPArpRngs)
dumpCmd.AddCommand(dumpCommand)
dumpCmd.AddCommand(dumpTelemetry)
dumpCmd.AddCommand(dumpTMemory)
dumpCmd.AddCommand(dumpTRuntime)
dumpCmd.AddCommand(dumpTNodeCount)
dumpCmd.AddCommand(dumpTracer)
dumpCmd.AddCommand(dumpIndex)
}

func linuxInterfaceDumpFunction(cmd *cobra.Command, args []string) {
msg := restapi.GetMsg(globalFlags.Endpoints, resturl.LinuxInterface)

Expand Down
64 changes: 30 additions & 34 deletions cmd/agentctl/cmd/generate.go → cmd/agentctl/commands/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package commands

import (
"encoding/json"
Expand All @@ -9,9 +9,8 @@ import (

"github.com/ghodss/yaml"
"github.com/gogo/protobuf/proto"
"github.com/spf13/cobra"

"github.com/ligato/cn-infra/servicelabel"
"github.com/spf13/cobra"

"github.com/ligato/vpp-agent/api/models/linux"
"github.com/ligato/vpp-agent/api/models/vpp"
Expand All @@ -20,14 +19,34 @@ import (
"github.com/ligato/vpp-agent/pkg/models"
)

// RootCmd represents the base command when called without any subcommands.
var generateConfig = &cobra.Command{
Use: "generate",
Aliases: []string{"g"},
Short: "Generate example command",
Long: `
Generate example command
`,
func generateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "generate",
Aliases: []string{"g"},
Short: "Generate example command",
}
cmd.AddCommand(generateACL)
cmd.AddCommand(generateInterface)
cmd.AddCommand(generateBd)
cmd.AddCommand(generateFib)
cmd.AddCommand(generateIPScanNeighbor)
cmd.AddCommand(generateNatGlobal)
cmd.AddCommand(generateNatDNat)
cmd.AddCommand(generateIPSecPolicy)
cmd.AddCommand(generateIPSecAssociation)
cmd.AddCommand(generateArps)
cmd.AddCommand(generateRoutes)
cmd.AddCommand(generatePArp)
cmd.AddCommand(generateLinuxInterface)
cmd.AddCommand(generateLinuxARP)
cmd.AddCommand(generateLinuxRoutes)

formatType = cmd.PersistentFlags().String("format", "json",
"Output formats:\n\tjson\n\tyaml\n\tproto\n")
cmd.PersistentFlags().BoolVar(&short, "short", false,
"Print command to one line. Work only with json format")

return cmd
}

var generateACL = &cobra.Command{
Expand Down Expand Up @@ -185,29 +204,6 @@ var (
short bool
)

func init() {
RootCmd.AddCommand(generateConfig)
generateConfig.AddCommand(generateACL)
generateConfig.AddCommand(generateInterface)
generateConfig.AddCommand(generateBd)
generateConfig.AddCommand(generateFib)
generateConfig.AddCommand(generateIPScanNeighbor)
generateConfig.AddCommand(generateNatGlobal)
generateConfig.AddCommand(generateNatDNat)
generateConfig.AddCommand(generateIPSecPolicy)
generateConfig.AddCommand(generateIPSecAssociation)
generateConfig.AddCommand(generateArps)
generateConfig.AddCommand(generateRoutes)
generateConfig.AddCommand(generatePArp)
generateConfig.AddCommand(generateLinuxInterface)
generateConfig.AddCommand(generateLinuxARP)
generateConfig.AddCommand(generateLinuxRoutes)
formatType = generateConfig.PersistentFlags().String("format", "json",
"Output formats:\n\tjson\n\tyaml\n\tproto\n")
generateConfig.PersistentFlags().BoolVar(&short, "short", false,
"Print command to one line. Work only with json format")
}

func aclGenerateFunction(cmd *cobra.Command, args []string) {
generateFunction(cmd_generator.ACL)
}
Expand Down
Loading

0 comments on commit 412d2fb

Please sign in to comment.