• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nagayon-935 / DrawlScan / 15916885410

27 Jun 2025 02:39AM UTC coverage: 78.889% (-2.6%) from 81.538%
15916885410

push

github

web-flow
Merge pull request #15 from nagayon-935/releases/v0.3.7

update: add cobra

10 of 27 new or added lines in 1 file covered. (37.04%)

1 existing line in 1 file now uncovered.

426 of 540 relevant lines covered (78.89%)

6.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.85
/cmd/handler/option_handler.go
1
package handler
2

3
import (
4
        "fmt"
5
        "reflect"
6

7
        "os"
8

9
        "github.com/spf13/cobra"
10
        "github.com/spf13/pflag"
11
        flag "github.com/spf13/pflag"
12
)
13

14
type analysisOption struct {
15
        Geoip  bool
16
        Filter string
17
}
18

19
type captureOption struct {
20
        Count int
21
        Time  int
22
}
23

24
type generalOption struct {
25
        Help    bool
26
        Version bool
27
}
28

29
type ioOption struct {
30
        InterfaceName string
31
        OutputFile    string
32
        ReadFile      string
33
}
34

35
type visualizationOption struct {
36
        Ascii   bool
37
        NoAscii bool
38
}
39

40
type completionOption struct {
41
        GenerateCompletions bool
42
}
43

44
type options struct {
45
        Analysis      *analysisOption
46
        Capture       *captureOption
47
        General       *generalOption
48
        Io            *ioOption
49
        Visualization *visualizationOption
50
        Completion    *completionOption
51
}
52

53
func HelpMessage() string {
1✔
54
        return `Usage: drawlscan [OPTIONS]
1✔
55

1✔
56
OPTIONS:
1✔
57
    -c, --count <NUM>              Capture only a specified number of packets
1✔
58
    -f, --filter <REGX>            Filter packets using a BPF (Berkeley Packet Filter) expression.
1✔
59
                                   You can specify filters such as:
1✔
60
                                     - ip src 192.168.1.1
1✔
61
                                     - ip dst 192.168.1.2
1✔
62
                                     - ip host 192.168.1.1 and ip host 192.168.1.2
1✔
63
                                     - tcp port 80
1✔
64
                                     - udp port 53
1✔
65
                                     - icmp or icmp6
1✔
66
                                     - vlan 100
1✔
67
                                     - ip host 192.168.1.1 and tcp port 80
1✔
68
    -g, --geoip                    Show GeoIP information for source and destination IP addresses
1✔
69
    -h, --help                     Display this help message
1✔
70
    -i, --interface <INTERFACE>    Specify the network interface to capture packets from (e.g., eth0, wlan0)
1✔
71
    -o, --output <FILE>            Save the captured packets to a file in PCAP format
1✔
72
    -r, --read <FILE>              Read packets from a PCAP file instead of capturing live traffic
1✔
73
    -t, --time <TIME>              Stop capturing after a specified number of seconds
1✔
74
    -v, --version                  Show version information
1✔
75
    --no-ascii                     Disable ASCII-art output
1✔
76
`
1✔
77
}
1✔
78

79
func buildFlagSet() (*flag.FlagSet, *options) {
2✔
80
        opts := &options{
2✔
81
                Capture:       &captureOption{},
2✔
82
                Analysis:      &analysisOption{},
2✔
83
                Visualization: &visualizationOption{},
2✔
84
                General:       &generalOption{},
2✔
85
                Io:            &ioOption{},
2✔
86
                Completion:    &completionOption{},
2✔
87
        }
2✔
88

2✔
89
        flags := flag.NewFlagSet("drawlscan", flag.ContinueOnError)
2✔
90
        flags.Usage = func() { fmt.Println(HelpMessage()) }
2✔
91

92
        flags.BoolVarP(&opts.Analysis.Geoip, "geoip", "g", false, "Show GeoIP information for source and destination IP addresses")
2✔
93
        flags.StringVarP(&opts.Analysis.Filter, "filter", "f", "", "Filter packets")
2✔
94

2✔
95
        flags.IntVarP(&opts.Capture.Count, "count", "c", -1, "Capture only a specified number of packets")
2✔
96
        flags.IntVarP(&opts.Capture.Time, "time", "t", -1, "Stop capturing after a specified number of seconds")
2✔
97

2✔
98
        flags.BoolVarP(&opts.General.Help, "help", "h", false, "Help message")
2✔
99
        flags.BoolVarP(&opts.General.Version, "version", "v", false, "Version information")
2✔
100

2✔
101
        flags.StringVarP(&opts.Io.InterfaceName, "interface", "i", "", "Specify the network interface to capture packets from (e.g., eth0, wlan0)")
2✔
102
        flags.StringVarP(&opts.Io.OutputFile, "output", "o", "", " Save the captured packets to a file in PCAP format")
2✔
103
        flags.StringVarP(&opts.Io.ReadFile, "read", "r", "", "Read packets from a PCAP file instead of capturing live traffic")
2✔
104

2✔
105
        flags.BoolVar(&opts.Visualization.NoAscii, "no-ascii", false, "Disable ASCII-art output")
2✔
106
        flags.BoolVarP(&opts.Completion.GenerateCompletions, "generate-completions", "", false, "generate completions")
2✔
107
        flags.MarkHidden("generate-completions")
2✔
108
        return flags, opts
2✔
109
}
110

111
func Options(optArgs []string) map[string]interface{} {
1✔
112
        flags, options := buildFlagSet()
1✔
113
        flags.Parse(optArgs[1:])
1✔
114
        if options.Completion.GenerateCompletions {
1✔
NEW
115
                GenerateCompletion(flags)
×
NEW
116
        }
×
117
        optionMap := make(map[string]interface{})
1✔
118
        collectFieldMap(reflect.ValueOf(options), optionMap)
1✔
119
        return optionMap
1✔
120
}
121

122
func collectFieldMap(value reflect.Value, optionMap map[string]interface{}) {
13✔
123
        if value.Kind() == reflect.Ptr {
26✔
124
                value = value.Elem()
13✔
125
        }
13✔
126
        valueType := value.Type()
13✔
127

13✔
128
        fields := reflect.VisibleFields(valueType)
13✔
129
        for _, field := range fields {
48✔
130
                fieldValue := value.FieldByIndex(field.Index)
35✔
131
                key := field.Name
35✔
132
                if fieldValue.Kind() == reflect.Struct || (fieldValue.Kind() == reflect.Ptr && !fieldValue.IsNil() && fieldValue.Elem().Kind() == reflect.Struct) {
46✔
133
                        collectFieldMap(fieldValue, optionMap)
11✔
134
                } else {
35✔
135
                        optionMap[key] = fieldValue.Interface()
24✔
136
                }
24✔
137
        }
138
}
139

NEW
140
func GenerateCompletion(flag *pflag.FlagSet) error {
×
NEW
141
        command := &cobra.Command{
×
NEW
142
                Use: "drawlscan",
×
NEW
143
        }
×
NEW
144
        command.Flags().AddFlagSet(flag)
×
NEW
145
        os.Mkdir("completions/", 0755)
×
NEW
146
        os.Mkdir("completions/bash", 0755)
×
NEW
147
        os.Mkdir("completions/zsh", 0755)
×
NEW
148
        os.Mkdir("completions/fish", 0755)
×
NEW
149
        os.Mkdir("completions/powershell", 0755)
×
NEW
150
        command.GenBashCompletionFileV2("completions/bash/drawlscan", true)
×
NEW
151
        command.GenZshCompletionFile("completions/zsh/drawlscan")
×
NEW
152
        command.GenFishCompletionFile("completions/fish/drawlscan", true)
×
NEW
153
        command.GenPowerShellCompletionFile("completions/powershell/drawlscan")
×
NEW
154
        return nil
×
UNCOV
155
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc