Conditions | 3 |
Total Lines | 85 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | package cmd |
||
18 | func NewScanCommand(logger *logrus.Logger) (*cobra.Command, error) { |
||
|
|||
19 | cmd := &cobra.Command{ |
||
20 | Use: "scan [url]", |
||
21 | Short: "Scan the given URL", |
||
22 | RunE: buildScanFunction(logger), |
||
23 | } |
||
24 | |||
25 | cmd.Flags().StringP( |
||
26 | flagDictionary, |
||
27 | flagDictionaryShort, |
||
28 | "", |
||
29 | "dictionary to use for the scan (path to local file or remote url)", |
||
30 | ) |
||
31 | err := cmd.MarkFlagFilename(flagDictionary) |
||
32 | if err != nil { |
||
33 | return nil, err |
||
34 | } |
||
35 | |||
36 | err = cmd.MarkFlagRequired(flagDictionary) |
||
37 | if err != nil { |
||
38 | return nil, err |
||
39 | } |
||
40 | |||
41 | cmd.Flags().StringSlice( |
||
42 | flagHTTPMethods, |
||
43 | []string{"GET"}, |
||
44 | "comma separated list of http methods to use; eg: GET,POST,PUT", |
||
45 | ) |
||
46 | |||
47 | cmd.Flags().IntP( |
||
48 | flagThreads, |
||
49 | flagThreadsShort, |
||
50 | 3, |
||
51 | "amount of threads for concurrent requests", |
||
52 | ) |
||
53 | |||
54 | cmd.Flags().IntP( |
||
55 | flagHTTPTimeout, |
||
56 | "", |
||
57 | 5000, |
||
58 | "timeout in milliseconds", |
||
59 | ) |
||
60 | |||
61 | cmd.Flags().IntP( |
||
62 | flagScanDepth, |
||
63 | "", |
||
64 | 3, |
||
65 | "scan depth", |
||
66 | ) |
||
67 | |||
68 | cmd.Flags().StringP( |
||
69 | flagSocks5Host, |
||
70 | "", |
||
71 | "", |
||
72 | "socks5 host to use", |
||
73 | ) |
||
74 | |||
75 | cmd.Flags().StringP( |
||
76 | flagUserAgent, |
||
77 | "", |
||
78 | "", |
||
79 | "user agent to use for http requests", |
||
80 | ) |
||
81 | |||
82 | cmd.Flags().BoolP( |
||
83 | flagCookieJar, |
||
84 | "", |
||
85 | false, |
||
86 | "enables the use of a cookie jar: it will retain any cookie sent "+ |
||
87 | "from the server and send them for the following requests", |
||
88 | ) |
||
89 | |||
90 | cmd.Flags().StringArray( |
||
91 | flagCookie, |
||
92 | []string{}, |
||
93 | "cookie to add to each request; eg name=value (can be specified multiple times)", |
||
94 | ) |
||
95 | |||
96 | cmd.Flags().StringArray( |
||
97 | flagHeader, |
||
98 | []string{}, |
||
99 | "header to add to each request; eg name=value (can be specified multiple times)", |
||
100 | ) |
||
101 | |||
102 | return cmd, nil |
||
103 | } |
||
219 |