| Conditions | 1 |
| Total Lines | 117 |
| Code Lines | 83 |
| 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().IntP( |
||
| 43 | flagScanDictionaryGetTimeout, |
||
| 44 | "", |
||
| 45 | 50000, |
||
| 46 | "timeout in milliseconds (used when fetching remote dictionary)", |
||
| 47 | ) |
||
| 48 | |||
| 49 | cmd.Flags().StringSlice( |
||
| 50 | flagScanHTTPMethods, |
||
| 51 | []string{"GET"}, |
||
| 52 | "comma separated list of http methods to use; eg: GET,POST,PUT", |
||
| 53 | ) |
||
| 54 | |||
| 55 | cmd.Flags().IntSlice( |
||
| 56 | flagScanHTTPStatusesToIgnore, |
||
| 57 | []int{http.StatusNotFound}, |
||
| 58 | "comma separated list of http statuses to ignore when showing and processing results; eg: 404,301", |
||
| 59 | ) |
||
| 60 | |||
| 61 | cmd.Flags().IntP( |
||
| 62 | flagScanThreads, |
||
| 63 | flagScanThreadsShort, |
||
| 64 | 3, |
||
| 65 | "amount of threads for concurrent requests", |
||
| 66 | ) |
||
| 67 | |||
| 68 | cmd.Flags().IntP( |
||
| 69 | flagScanHTTPTimeout, |
||
| 70 | "", |
||
| 71 | 5000, |
||
| 72 | "timeout in milliseconds", |
||
| 73 | ) |
||
| 74 | |||
| 75 | cmd.Flags().BoolP( |
||
| 76 | flagScanHTTPCacheRequests, |
||
| 77 | "", |
||
| 78 | true, |
||
| 79 | "cache requests to avoid performing the same request multiple times within the same scan (EG if the "+ |
||
| 80 | "server reply with the same redirect location multiple times, dirstalk will follow it only once)", |
||
| 81 | ) |
||
| 82 | |||
| 83 | cmd.Flags().IntP( |
||
| 84 | flagScanScanDepth, |
||
| 85 | "", |
||
| 86 | 3, |
||
| 87 | "scan depth", |
||
| 88 | ) |
||
| 89 | |||
| 90 | cmd.Flags().StringP( |
||
| 91 | flagScanSocks5Host, |
||
| 92 | "", |
||
| 93 | "", |
||
| 94 | "socks5 host to use", |
||
| 95 | ) |
||
| 96 | |||
| 97 | cmd.Flags().StringP( |
||
| 98 | flagScanUserAgent, |
||
| 99 | "", |
||
| 100 | "", |
||
| 101 | "user agent to use for http requests", |
||
| 102 | ) |
||
| 103 | |||
| 104 | cmd.Flags().BoolP( |
||
| 105 | flagScanCookieJar, |
||
| 106 | "", |
||
| 107 | false, |
||
| 108 | "enables the use of a cookie jar: it will retain any cookie sent "+ |
||
| 109 | "from the server and send them for the following requests", |
||
| 110 | ) |
||
| 111 | |||
| 112 | cmd.Flags().StringArray( |
||
| 113 | flagScanCookie, |
||
| 114 | []string{}, |
||
| 115 | "cookie to add to each request; eg name=value (can be specified multiple times)", |
||
| 116 | ) |
||
| 117 | |||
| 118 | cmd.Flags().StringArray( |
||
| 119 | flagScanHeader, |
||
| 120 | []string{}, |
||
| 121 | "header to add to each request; eg name=value (can be specified multiple times)", |
||
| 122 | ) |
||
| 123 | |||
| 124 | cmd.Flags().String( |
||
| 125 | flagScanResultOutput, |
||
| 126 | "", |
||
| 127 | "path where to store result output", |
||
| 128 | ) |
||
| 129 | |||
| 130 | cmd.Flags().Bool( |
||
| 131 | flagShouldSkipSSLCertificatesValidation, |
||
| 132 | false, |
||
| 133 | "to skip checking the validity of SSL certificates", |
||
| 134 | ) |
||
| 135 | |||
| 136 | cmd.Flags().Bool( |
||
| 137 | flagIgnore20xWithEmptyBody, |
||
| 138 | false, |
||
| 139 | "ignore HTTP 20x responses with empty body", |
||
| 140 | ) |
||
| 141 | |||
| 142 | return cmd |
||
| 143 | } |
||
| 363 |