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;
3333
3434const char *prog_name;
3535
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+
3650class DockerFileTransformer {
3751 public:
3852 DockerFileTransformer (const TStringList &prefixCmd, const bool verbose):
@@ -353,13 +367,9 @@ int main(int argc, char *argv[])
353367
354368 const bool verbose = !!vm.count (" verbose" );
355369
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" )) {
363373 desc.print (std::cerr);
364374 return 1 ;
365375 }
You can’t perform that action at this time.
0 commit comments