@@ -47,11 +47,16 @@ bool readListFromValMap(TDst *pDst, const TMap &vm, const char *key)
47
47
return !dst.empty ();
48
48
}
49
49
50
+ // / transformation properties set on cmd-line
51
+ struct TransformerProps {
52
+ TStringList prefixCmd; // /< cmd-line operands
53
+ bool verbose; // /< if true, print in/out of each transformation
54
+ };
55
+
50
56
class DockerFileTransformer {
51
57
public:
52
- DockerFileTransformer (const TStringList &prefixCmd, const bool verbose):
53
- prefixCmd_ (prefixCmd),
54
- verbose_ (verbose),
58
+ DockerFileTransformer (const TransformerProps &tp):
59
+ tp_ (tp),
55
60
lineNum_ (0 )
56
61
{
57
62
}
@@ -60,9 +65,8 @@ class DockerFileTransformer {
60
65
bool transform (std::istream &in, std::ostream &out);
61
66
62
67
private:
63
- const TStringList prefixCmd_; // /< cmd-line operands
64
- const bool verbose_; // /< --verbose on cmd-line
65
- int lineNum_; // /< line number being read
68
+ const TransformerProps tp_; // /< props set on cmd-line
69
+ int lineNum_; // /< line number being read
66
70
67
71
void transformRunLine (std::string *);
68
72
@@ -192,7 +196,7 @@ void DockerFileTransformer::transformRunLine(std::string *pRunLine)
192
196
const std::string cmd = sm[2 ];
193
197
194
198
// start with the prefix specified on cmd-line
195
- TStringList execList = prefixCmd_ ;
199
+ TStringList execList = tp_. prefixCmd ;
196
200
197
201
if (boost::regex_match (cmd, sm, reLineRunExec_))
198
202
// ["cmd", "arg1", "arg2", ...]
@@ -202,7 +206,7 @@ void DockerFileTransformer::transformRunLine(std::string *pRunLine)
202
206
appendShellExec (&execList, cmd);
203
207
204
208
newRunLine += runCmdFromExecList (execList);
205
- if (verbose_ ) {
209
+ if (tp_. verbose ) {
206
210
// diagnostic output printed with --verbose
207
211
std::cerr << prog_name << " <<< " << *pRunLine << std::endl;
208
212
std::cerr << prog_name << " >>> " << newRunLine << std::endl;
@@ -365,17 +369,18 @@ int main(int argc, char *argv[])
365
369
return 0 ;
366
370
}
367
371
368
- const bool verbose = !!vm.count (" verbose" );
372
+ // read cmd-line flags
373
+ TransformerProps tp;
374
+ tp.verbose = !!vm.count (" verbose" );
369
375
370
376
// read the prefix command
371
- TStringList prefixCmd;
372
- if (!readListFromValMap (&prefixCmd, vm, " prefix-cmd" )) {
377
+ if (!readListFromValMap (&tp.prefixCmd , vm, " prefix-cmd" )) {
373
378
desc.print (std::cerr);
374
379
return 1 ;
375
380
}
376
381
377
- // pass cmd-line args to DockerFileTransformer
378
- DockerFileTransformer dft (prefixCmd, verbose );
382
+ // create the transformer object
383
+ DockerFileTransformer dft (tp );
379
384
380
385
if (vm.count (" in-place" ))
381
386
// transform Dockerfile in-place
0 commit comments