| 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 | ||
| 17 | func NewScanCommand(logger *logrus.Logger) (*cobra.Command, error) { | ||
|  | |||
| 18 | 	cmd := &cobra.Command{ | ||
| 19 | Use: "scan [url]", | ||
| 20 | Short: "Scan the given URL", | ||
| 21 | RunE: buildScanFunction(logger), | ||
| 22 | } | ||
| 23 | |||
| 24 | cmd.Flags().StringP( | ||
| 25 | flagDictionary, | ||
| 26 | flagDictionaryShort, | ||
| 27 | "", | ||
| 28 | "dictionary to use for the scan (path to local file or remote url)", | ||
| 29 | ) | ||
| 30 | err := cmd.MarkFlagFilename(flagDictionary) | ||
| 31 | 	if err != nil { | ||
| 32 | return nil, err | ||
| 33 | } | ||
| 34 | |||
| 35 | err = cmd.MarkFlagRequired(flagDictionary) | ||
| 36 | 	if err != nil { | ||
| 37 | return nil, err | ||
| 38 | } | ||
| 39 | |||
| 40 | cmd.Flags().StringSlice( | ||
| 41 | flagHTTPMethods, | ||
| 42 | 		[]string{"GET"}, | ||
| 43 | "comma separated list of http methods to use; eg: GET,POST,PUT", | ||
| 44 | ) | ||
| 45 | |||
| 46 | cmd.Flags().IntP( | ||
| 47 | flagThreads, | ||
| 48 | flagThreadsShort, | ||
| 49 | 3, | ||
| 50 | "amount of threads for concurrent requests", | ||
| 51 | ) | ||
| 52 | |||
| 53 | cmd.Flags().IntP( | ||
| 54 | flagHTTPTimeout, | ||
| 55 | "", | ||
| 56 | 5000, | ||
| 57 | "timeout in milliseconds", | ||
| 58 | ) | ||
| 59 | |||
| 60 | cmd.Flags().IntP( | ||
| 61 | flagScanDepth, | ||
| 62 | "", | ||
| 63 | 3, | ||
| 64 | "scan depth", | ||
| 65 | ) | ||
| 66 | |||
| 67 | cmd.Flags().StringP( | ||
| 68 | flagSocks5Host, | ||
| 69 | "", | ||
| 70 | "", | ||
| 71 | "socks5 host to use", | ||
| 72 | ) | ||
| 73 | |||
| 74 | cmd.Flags().StringP( | ||
| 75 | flagUserAgent, | ||
| 76 | "", | ||
| 77 | "", | ||
| 78 | "user agent to use for http requests", | ||
| 79 | ) | ||
| 80 | |||
| 81 | cmd.Flags().BoolP( | ||
| 82 | flagCookieJar, | ||
| 83 | "", | ||
| 84 | false, | ||
| 85 | "enables the use of a cookie jar: it will retain any cookie sent "+ | ||
| 86 | "from the server and send them for the following requests", | ||
| 87 | ) | ||
| 88 | |||
| 89 | cmd.Flags().StringArray( | ||
| 90 | flagCookie, | ||
| 91 | 		[]string{}, | ||
| 92 | "cookie to add to each request; eg name=value (can be specified multiple times)", | ||
| 93 | ) | ||
| 94 | |||
| 95 | cmd.Flags().StringArray( | ||
| 96 | flagHeader, | ||
| 97 | 		[]string{}, | ||
| 98 | "header to add to each request; eg name=value (can be specified multiple times)", | ||
| 99 | ) | ||
| 100 | |||
| 101 | return cmd, nil | ||
| 102 | } | ||
| 213 |