Skip to content

Commit

Permalink
Add cli cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Foerster <tim.foerster@hetzner.de>
  • Loading branch information
tonobo committed Dec 14, 2017
1 parent cb34af2 commit 8845a8c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
38 changes: 38 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"errors"
"fmt"
"time"

"github.com/spf13/cobra"
)

var (
COUNT = 5
MAX_HOPS = 64
RING_BUFFER_SIZE = 8
)

// rootCmd represents the root command
var RootCmd = &cobra.Command{
Use: "mtr TARGET",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("No target provided")
}
fmt.Println("Start:", time.Now())
m := NewMTR(args[0])
for i := 0; i < COUNT; i++ {
m.Run()
}
m.Render()
return nil
},
}

func init() {
RootCmd.Flags().IntVarP(&COUNT, "count", "c", COUNT, "Amount of pings per target")
RootCmd.Flags().IntVar(&MAX_HOPS, "max-hops", MAX_HOPS, "Maximal TTL count")
RootCmd.Flags().IntVar(&RING_BUFFER_SIZE, "buffer-size", RING_BUFFER_SIZE, "Cached packet buffer size")
}
17 changes: 1 addition & 16 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
package main

import (
"fmt"
"time"
)

var (
MAX_HOPS = 64
RING_BUFFER_SIZE = 8
)

func main() {
fmt.Println("Start:", time.Now())
m := NewMTR("8.8.8.8")
m.Run()
m.Run()
m.Run()
m.Render()
RootCmd.Execute()
}

0 comments on commit 8845a8c

Please sign in to comment.