Conditions | 1 |
Total Lines | 98 |
Code Lines | 70 |
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 |
||
26 | func NewScanCommand(logger *logrus.Logger) *cobra.Command { |
||
27 | cmd := &cobra.Command{ |
||
28 | Use: "scan [url]", |
||
29 | Short: "Scan the given URL", |
||
30 | RunE: buildScanFunction(logger), |
||
31 | } |
||
32 | |||
33 | cmd.Flags().StringP( |
||
34 | flagScanDictionary, |
||
35 | flagScanDictionaryShort, |
||
36 | "", |
||
37 | "dictionary to use for the scan (path to local file or remote url)", |
||
38 | ) |
||
39 | common.Must(cmd.MarkFlagFilename(flagScanDictionary)) |
||
40 | common.Must(cmd.MarkFlagRequired(flagScanDictionary)) |
||
41 | |||
42 | cmd.Flags().StringSlice( |
||
43 | flagScanHTTPMethods, |
||
44 | []string{"GET"}, |
||
45 | "comma separated list of http methods to use; eg: GET,POST,PUT", |
||
46 | ) |
||
47 | |||
48 | cmd.Flags().IntSlice( |
||
49 | flagScanHTTPStatusesToIgnore, |
||
50 | []int{http.StatusNotFound}, |
||
51 | "comma separated list of http statuses to ignore when showing and processing results; eg: 404,301", |
||
52 | ) |
||
53 | |||
54 | cmd.Flags().IntP( |
||
55 | flagScanThreads, |
||
56 | flagScanThreadsShort, |
||
57 | 3, |
||
58 | "amount of threads for concurrent requests", |
||
59 | ) |
||
60 | |||
61 | cmd.Flags().IntP( |
||
62 | flagScanHTTPTimeout, |
||
63 | "", |
||
64 | 5000, |
||
65 | "timeout in milliseconds", |
||
66 | ) |
||
67 | |||
68 | cmd.Flags().BoolP( |
||
69 | flagScanHTTPCacheRequests, |
||
70 | "", |
||
71 | true, |
||
72 | "cache requests to avoid performing the same request multiple times within the same scan (EG if the "+ |
||
73 | "server reply with the same redirect location multiple times, dirstalk will follow it only once)", |
||
74 | ) |
||
75 | |||
76 | cmd.Flags().IntP( |
||
77 | flagScanScanDepth, |
||
78 | "", |
||
79 | 3, |
||
80 | "scan depth", |
||
81 | ) |
||
82 | |||
83 | cmd.Flags().StringP( |
||
84 | flagScanSocks5Host, |
||
85 | "", |
||
86 | "", |
||
87 | "socks5 host to use", |
||
88 | ) |
||
89 | |||
90 | cmd.Flags().StringP( |
||
91 | flagScanUserAgent, |
||
92 | "", |
||
93 | "", |
||
94 | "user agent to use for http requests", |
||
95 | ) |
||
96 | |||
97 | cmd.Flags().BoolP( |
||
98 | flagScanCookieJar, |
||
99 | "", |
||
100 | false, |
||
101 | "enables the use of a cookie jar: it will retain any cookie sent "+ |
||
102 | "from the server and send them for the following requests", |
||
103 | ) |
||
104 | |||
105 | cmd.Flags().StringArray( |
||
106 | flagScanCookie, |
||
107 | []string{}, |
||
108 | "cookie to add to each request; eg name=value (can be specified multiple times)", |
||
109 | ) |
||
110 | |||
111 | cmd.Flags().StringArray( |
||
112 | flagScanHeader, |
||
113 | []string{}, |
||
114 | "header to add to each request; eg name=value (can be specified multiple times)", |
||
115 | ) |
||
116 | |||
117 | cmd.Flags().String( |
||
118 | flagScanResultOutput, |
||
119 | "", |
||
120 | "path where to store result output", |
||
121 | ) |
||
122 | |||
123 | return cmd |
||
124 | } |
||
288 |