| Conditions | 3 |
| Total Lines | 65 |
| Code Lines | 46 |
| 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 |
||
| 14 | func NewScanCommand(logger *logrus.Logger) (*cobra.Command, error) { |
||
|
|
|||
| 15 | cmd := &cobra.Command{ |
||
| 16 | Use: "scan [url]", |
||
| 17 | Short: "Scan the given URL", |
||
| 18 | RunE: buildScanFunction(logger), |
||
| 19 | } |
||
| 20 | |||
| 21 | cmd.Flags().StringP( |
||
| 22 | flagDictionary, |
||
| 23 | flagDictionaryShort, |
||
| 24 | "", |
||
| 25 | "dictionary to use for the scan (path to local file or remote url)", |
||
| 26 | ) |
||
| 27 | err := cmd.MarkFlagFilename(flagDictionary) |
||
| 28 | if err != nil { |
||
| 29 | return nil, err |
||
| 30 | } |
||
| 31 | |||
| 32 | err = cmd.MarkFlagRequired(flagDictionary) |
||
| 33 | if err != nil { |
||
| 34 | return nil, err |
||
| 35 | } |
||
| 36 | |||
| 37 | cmd.Flags().StringSlice( |
||
| 38 | flagHTTPMethods, |
||
| 39 | []string{"GET"}, |
||
| 40 | "comma separated list of http methods to use; eg: GET,POST,PUT", |
||
| 41 | ) |
||
| 42 | |||
| 43 | cmd.Flags().IntP( |
||
| 44 | flagThreads, |
||
| 45 | flagThreadsShort, |
||
| 46 | 3, |
||
| 47 | "amount of threads for concurrent requests", |
||
| 48 | ) |
||
| 49 | |||
| 50 | cmd.Flags().IntP( |
||
| 51 | flagHTTPTimeout, |
||
| 52 | "", |
||
| 53 | 5000, |
||
| 54 | "timeout in milliseconds", |
||
| 55 | ) |
||
| 56 | |||
| 57 | cmd.Flags().IntP( |
||
| 58 | flagScanDepth, |
||
| 59 | "", |
||
| 60 | 3, |
||
| 61 | "scan depth", |
||
| 62 | ) |
||
| 63 | |||
| 64 | cmd.Flags().StringP( |
||
| 65 | flagSocks5Host, |
||
| 66 | "", |
||
| 67 | "", |
||
| 68 | "socks5 host to use", |
||
| 69 | ) |
||
| 70 | |||
| 71 | cmd.Flags().StringP( |
||
| 72 | flagUserAgent, |
||
| 73 | "", |
||
| 74 | "", |
||
| 75 | "user agent to use for http requests", |
||
| 76 | ) |
||
| 77 | |||
| 78 | return cmd, nil |
||
| 79 | } |
||
| 122 |