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