@@ -73,23 +73,42 @@ def _register_arguments(parser):
73
73
# update
74
74
subparsers .add_parser ('update' , help = 'Updates Manof' )
75
75
76
+ # base sub parser
77
+ base_command_parent_parser = argparse .ArgumentParser (add_help = False )
78
+ base_command_parent_parser .add_argument ('targets' , nargs = '+' )
79
+ base_command_parent_parser .add_argument ('-e' ,
80
+ '--exclude' ,
81
+ help = 'Exclude targets when running manof cmd (comma-delimited, no spaces)' ,
82
+ default = '' )
83
+
84
+ # TODO: Change default to 'docker.io'. Currently default is None for backwards compatibility
85
+ base_command_parent_parser .add_argument ('-r' ,
86
+ '--repository' ,
87
+ help = 'The repository from which images shall be taken from or pushed to' ,
88
+ default = None )
89
+
90
+ # image based commands
91
+ provision_parent_command = argparse .ArgumentParser (add_help = False )
92
+ provision_parent_command .add_argument ('-n' , '--no-cache' ,
93
+ help = 'Don\' t use cache images on build' ,
94
+ action = 'store_true' )
95
+ provision_parent_command .add_argument ('--force-rm' ,
96
+ help = 'Image: Always remove intermediate containers. '
97
+ 'NamedVolume: Delete existing before creation' ,
98
+ action = 'store_true' )
99
+ provision_parent_command .add_argument ('-tl' ,
100
+ '--skip-tag-local' ,
101
+ help = 'If no context is given, provision will perform pull and '
102
+ 'skip tagging the image with its local repository (default: False)' ,
103
+ dest = 'tag_local' ,
104
+ action = 'store_false' )
105
+
76
106
# provision
77
- provision_command = subparsers .add_parser ('provision' , help = 'Build or pull target images' )
78
- provision_command .add_argument ('targets' , nargs = '+' )
79
- provision_command .add_argument ('-n' , '--no-cache' , help = 'Don\' t use cache images on build' , action = 'store_true' )
80
- provision_command .add_argument ('--force-rm' ,
81
- help = 'Image: Always remove intermediate containers. '
82
- 'NamedVolume: Delete existing before creation' ,
83
- action = 'store_true' )
84
- provision_command .add_argument ('-tl' ,
85
- '--skip-tag-local' ,
86
- help = 'If no context is given, provision will perform pull and '
87
- 'skip tagging the image with its local repository (default: False)' ,
88
- dest = 'tag_local' ,
89
- action = 'store_false' )
107
+ subparsers .add_parser ('provision' ,
108
+ help = 'Build or pull target images' ,
109
+ parents = [base_command_parent_parser , provision_parent_command ])
90
110
91
111
run_parent_parser = argparse .ArgumentParser (add_help = False )
92
- run_parent_parser .add_argument ('targets' , nargs = '+' )
93
112
run_parent_parser .add_argument ('--privileged' ,
94
113
action = 'store_true' ,
95
114
help = 'Give extended privileges to these containers' )
@@ -110,101 +129,72 @@ def _register_arguments(parser):
110
129
help = 'Limit write rate (IO per second) to a device (e.g. /dev/sda:50)' )
111
130
run_parent_parser .add_argument ('--cap-add' , help = 'Add capability to the container' , action = 'append' )
112
131
run_parent_parser .add_argument ('--cap-drop' , help = 'Drop capability from the container' , action = 'append' )
132
+ run_parent_parser .add_argument ('-dv' ,
133
+ '--delete-volumes' ,
134
+ help = 'Image: Delete named_volumes that are used by this image' ,
135
+ action = 'store_true' )
136
+ run_parent_parser .add_argument ('-pco' ,
137
+ '--print-command-only' ,
138
+ help = 'Will enforce dry run and print the run command only, no logs at all' ,
139
+ action = 'store_true' )
113
140
114
141
# run
115
- run_command = subparsers .add_parser ('run' , help = 'Run target containers' , parents = [run_parent_parser ])
116
- run_command .add_argument ('-dv' ,
117
- '--delete-volumes' ,
118
- help = 'Image: Delete named_volumes that are used by this image' ,
119
- action = 'store_true' )
120
- run_command .add_argument ('-pco' ,
121
- '--print-command-only' ,
122
- help = 'Will enforce dry run and print the run command only, no logs at all' ,
123
- action = 'store_true' )
142
+ subparsers .add_parser ('run' ,
143
+ help = 'Run target containers' ,
144
+ parents = [base_command_parent_parser , run_parent_parser ])
124
145
125
146
# stop
126
- stop_command = subparsers .add_parser ('stop' , help = 'Stop target containers' )
147
+ stop_command = subparsers .add_parser ('stop' ,
148
+ help = 'Stop target containers' ,
149
+ parents = [base_command_parent_parser ])
127
150
stop_command .add_argument ('-t' ,
128
151
'--time' ,
129
152
help = 'Seconds to wait for stop before killing it (default=10)' ,
130
153
type = int ,
131
154
default = 10 )
132
- stop_command .add_argument ('targets' , nargs = '+' )
133
155
134
156
# rm
135
- rm_command = subparsers .add_parser ('rm' , help = 'Remove targets' )
157
+ rm_command = subparsers .add_parser ('rm' ,
158
+ help = 'Remove targets' ,
159
+ parents = [base_command_parent_parser ])
136
160
rm_command .add_argument ('-f' , '--force' , help = 'Kill targets even if they are running' , action = 'store_true' )
137
161
rm_command .add_argument ('-v' ,
138
162
'--volumes' ,
139
163
help = 'Remove the volumes associated with the container' ,
140
164
action = 'store_true' )
141
- rm_command .add_argument ('targets' , nargs = '+' )
142
-
143
- # lift
144
- lift_command = subparsers .add_parser ('lift' , help = 'Provision and run targets' , parents = [run_parent_parser ])
145
-
146
- # TODO: Make a more pluginable args parser. (Copied lift's args from run and provision)
147
- lift_command .add_argument ('-dv' ,
148
- '--delete-volumes' ,
149
- help = 'Image: Delete named_volumes that are used by this image' ,
150
- action = 'store_true' )
151
- lift_command .add_argument ('-pco' ,
152
- '--print-command-only' ,
153
- help = 'Will enforce dry run and print the run command only, no logs at all' ,
154
- action = 'store_true' )
155
- lift_command .add_argument ('-n' , '--no-cache' , help = 'Don\' t use cache images on build' , action = 'store_true' )
156
- lift_command .add_argument ('--force-rm' ,
157
- help = 'Image: Always remove intermediate containers. '
158
- 'NamedVolume: Delete existing before creation' ,
159
- action = 'store_true' )
160
- lift_command .add_argument ('-tl' ,
161
- '--skip-tag-local' ,
162
- help = 'If no context is given, provision will perform pull and '
163
- 'skip tagging the image with its local repository (default: False)' ,
164
- dest = 'tag_local' ,
165
- action = 'store_false' )
166
165
167
166
# serialize
168
- serialize_command = subparsers .add_parser ('serialize' , help = 'Get a JSON representation of the targets' )
169
- serialize_command .add_argument ('targets' , nargs = '+' )
167
+ subparsers .add_parser ('serialize' ,
168
+ help = 'Get a JSON representation of the targets' ,
169
+ parents = [base_command_parent_parser ])
170
170
171
171
# push
172
- push_command = subparsers .add_parser ('push' , help = 'Push targets' )
173
- push_command .add_argument ('targets' , nargs = '+' )
172
+ push_command = subparsers .add_parser ('push' ,
173
+ help = 'Push targets' ,
174
+ parents = [base_command_parent_parser ])
174
175
push_command .add_argument ('-nc' ,
175
176
'--no-cleanup' ,
176
177
help = 'After pushing, delete the tagged image created to push' ,
177
178
action = 'store_true' )
178
179
179
180
# pull
180
- pull_command = subparsers .add_parser ('pull' , help = 'Pull targets' )
181
- pull_command .add_argument ('targets' , nargs = '+' )
182
- pull_command .add_argument ('-tl' ,
183
- '--tag-local' ,
184
- help = 'After pulling, tag the image with its local repository' ,
185
- action = 'store_true' )
181
+ pull_parent_parser = argparse .ArgumentParser (add_help = False )
182
+ pull_parent_parser .add_argument ('-tl' ,
183
+ '--tag-local' ,
184
+ help = 'After pulling, tag the image with its local repository' ,
185
+ action = 'store_true' )
186
+ subparsers .add_parser ('pull' ,
187
+ help = 'Pull targets' ,
188
+ parents = [base_command_parent_parser , pull_parent_parser ])
186
189
187
- # options common to all commands:
188
- for cmd_parse in [
189
- provision_command ,
190
- run_command ,
191
- stop_command ,
192
- rm_command ,
193
- lift_command ,
194
- push_command ,
195
- pull_command ,
196
- serialize_command
197
- ]:
198
- cmd_parse .add_argument ('-e' ,
199
- '--exclude' ,
200
- help = 'Exclude targets when running manof cmd (comma-delimited, no spaces)' ,
201
- default = '' )
202
-
203
- # TODO: Change default to 'docker.io'. Currently default is None for backwards compatibility
204
- cmd_parse .add_argument ('-r' ,
205
- '--repository' ,
206
- help = 'The repository from which images shall be taken from or pushed to' ,
207
- default = None )
190
+ # lift
191
+ subparsers .add_parser ('lift' ,
192
+ help = 'Provision and run targets' ,
193
+ parents = [
194
+ base_command_parent_parser ,
195
+ provision_parent_command ,
196
+ run_parent_parser ,
197
+ ])
208
198
209
199
known_option_strings = parser ._option_string_actions .keys ()
210
200
0 commit comments