Conditions | 1 |
Total Lines | 90 |
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 | #!/usr/bin/env python2 |
||
9 | def parse_args(): |
||
10 | parser = argparse.ArgumentParser() |
||
11 | |||
12 | parser.add_argument( |
||
13 | "--libvirt", |
||
14 | dest="libvirt", |
||
15 | default="qemu:///session", |
||
16 | help="What hypervisor should be used when installing VM." |
||
17 | ) |
||
18 | parser.add_argument( |
||
19 | "--kickstart", |
||
20 | dest="kickstart", |
||
21 | default="kickstarts/test_suite.cfg", |
||
22 | help="Path to a kickstart file for installation of a VM." |
||
23 | ) |
||
24 | parser.add_argument( |
||
25 | "--distro", |
||
26 | dest="distro", |
||
27 | required=True, |
||
28 | choices=['fedora', 'rhel7', 'centos7', 'rhel8'], |
||
29 | help="What distribution to install." |
||
30 | ) |
||
31 | parser.add_argument( |
||
32 | "--domain", |
||
33 | dest="domain", |
||
34 | required=True, |
||
35 | help="What name should the new domain have." |
||
36 | ) |
||
37 | parser.add_argument( |
||
38 | "--disk-dir", |
||
39 | dest="disk_dir", |
||
40 | default=None, |
||
41 | help="Location of the VM qcow2 file." |
||
42 | ) |
||
43 | parser.add_argument( |
||
44 | "--ram", |
||
45 | dest="ram", |
||
46 | default=2048, |
||
47 | type=int, |
||
48 | help="Amount of RAM configured for the VM." |
||
49 | ) |
||
50 | parser.add_argument( |
||
51 | "--cpu", |
||
52 | dest="cpu", |
||
53 | default=2, |
||
54 | type=int, |
||
55 | help="Number of CPU cores configured for the VM." |
||
56 | ) |
||
57 | parser.add_argument( |
||
58 | "--network", |
||
59 | dest="network", |
||
60 | help="Network type/spec, ie. bridge=br0 or network=name." |
||
61 | ) |
||
62 | parser.add_argument( |
||
63 | "--disk", |
||
64 | dest="disk", |
||
65 | help="Disk type/spec, ie. pool=MyPool,bus=sata,cache=unsafe." |
||
66 | ) |
||
67 | parser.add_argument( |
||
68 | "--url", |
||
69 | dest="url", |
||
70 | default=None, |
||
71 | help="URL to an installation tree on a remote server." |
||
72 | ) |
||
73 | parser.add_argument( |
||
74 | "--extra-repo", |
||
75 | dest="extra_repo", |
||
76 | default=None, |
||
77 | help="URL to an extra repository to be used during installation (e.g. AppStream)." |
||
78 | ) |
||
79 | parser.add_argument( |
||
80 | "--dry", |
||
81 | dest="dry", |
||
82 | action="store_true", |
||
83 | help="Print command line instead of triggering command." |
||
84 | ) |
||
85 | parser.add_argument( |
||
86 | "--ssh-pubkey", |
||
87 | dest="ssh_pubkey", |
||
88 | default=None, |
||
89 | help="Path to an SSH public key which will be used to access the VM." |
||
90 | ) |
||
91 | parser.add_argument( |
||
92 | "--uefi", |
||
93 | dest="uefi", |
||
94 | choices=['secureboot', 'normal'], |
||
95 | help="Perform UEFI based installation, optionally with secure boot support." |
||
96 | ) |
||
97 | |||
98 | return parser.parse_args() |
||
99 | |||
206 |