ttr.git


ttr

~ tiny traceroute in golang
git clone https://github.com/djnnvx/ttr.git
log | files | refs | archive | README | LICENSE

parser.go (1365B)

      1 package cli
      2 
      3 import (
      4 	"github.com/djnnvx/ttr/net"
      5 	"github.com/spf13/cobra"
      6 )
      7 
      8 const ASCII_ART = `
      9 
     10  ███████████ ███████████ ███████████
     11 ▒█▒▒▒███▒▒▒█▒█▒▒▒███▒▒▒█▒▒███▒▒▒▒▒███
     12 ▒   ▒███  ▒ ▒   ▒███  ▒  ▒███    ▒███
     13     ▒███        ▒███     ▒██████████
     14     ▒███        ▒███     ▒███▒▒▒▒▒███
     15     ▒███        ▒███     ▒███    ▒███
     16     █████       █████    █████   █████
     17    ▒▒▒▒▒       ▒▒▒▒▒    ▒▒▒▒▒   ▒▒▒▒▒
     18 
     19 
     20 
     21  ====== version 0.1.1 ======== djnn.sh
     22 
     23 `
     24 
     25 func GetParser(opts *TtrOptions) *cobra.Command {
     26 
     27 	var cmd = &cobra.Command{
     28 		Use:     "ttr",
     29 		Short:   "tiny traceroute utility",
     30 		Long:    ASCII_ART,
     31 		Args:    cobra.MinimumNArgs(1),
     32 		Version: "0.1.1",
     33 		Run: func(cmd *cobra.Command, args []string) {
     34 
     35 			println(ASCII_ART)
     36 
     37 			ipType := "ip4"
     38 			if opts.ForceIPv6 {
     39 				ipType = "ip6"
     40 			}
     41 
     42 			target := args[0]
     43 			net.Run(target, ipType)
     44 
     45 		},
     46 	}
     47 
     48 	defaults := GetDefaultOptions()
     49 
     50 	cmd.Flags().BoolVarP(&opts.ForceIPv6, "v6", "", defaults.ForceIPv6, "Force IPv6 usage")
     51 	return cmd
     52 }