File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,20 @@ typedef std::vector<std::string> TStringList;
33
33
34
34
const char *prog_name;
35
35
36
+ // / read non-empty list from value map "vm" with key "key" and store to "dst"
37
+ template <class TDst , class TMap >
38
+ bool readListFromValMap (TDst *pDst, const TMap &vm, const char *key)
39
+ {
40
+ if (!vm.count (key))
41
+ // "key" not found in "vm"
42
+ return false ;
43
+
44
+ // store the list to "*pDst" and return "true" if the list is not empty
45
+ TDst &dst = *pDst;
46
+ dst = vm[key].template as <TDst>();
47
+ return !dst.empty ();
48
+ }
49
+
36
50
class DockerFileTransformer {
37
51
public:
38
52
DockerFileTransformer (const TStringList &prefixCmd, const bool verbose):
@@ -353,13 +367,9 @@ int main(int argc, char *argv[])
353
367
354
368
const bool verbose = !!vm.count (" verbose" );
355
369
356
- if (!vm.count (" prefix-cmd" )) {
357
- desc.print (std::cerr);
358
- return 1 ;
359
- }
360
-
361
- const TStringList &prefixCmd = vm[" prefix-cmd" ].as <TStringList>();
362
- if (prefixCmd.empty ()) {
370
+ // read the prefix command
371
+ TStringList prefixCmd;
372
+ if (!readListFromValMap (&prefixCmd, vm, " prefix-cmd" )) {
363
373
desc.print (std::cerr);
364
374
return 1 ;
365
375
}
You can’t perform that action at this time.
0 commit comments