Skip to content

Commit 5e89e70

Browse files
committedFeb 5, 2025
cstrans-df-run: introduce TransformerProps struct
... to make the code easier to extend. No change in behavior intended with this commit.
1 parent 4e74860 commit 5e89e70

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed
 

‎src/cstrans-df-run.cc

+18-13
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@ bool readListFromValMap(TDst *pDst, const TMap &vm, const char *key)
4747
return !dst.empty();
4848
}
4949

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+
5056
class DockerFileTransformer {
5157
public:
52-
DockerFileTransformer(const TStringList &prefixCmd, const bool verbose):
53-
prefixCmd_(prefixCmd),
54-
verbose_(verbose),
58+
DockerFileTransformer(const TransformerProps &tp):
59+
tp_(tp),
5560
lineNum_(0)
5661
{
5762
}
@@ -60,9 +65,8 @@ class DockerFileTransformer {
6065
bool transform(std::istream &in, std::ostream &out);
6166

6267
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
6670

6771
void transformRunLine(std::string *);
6872

@@ -192,7 +196,7 @@ void DockerFileTransformer::transformRunLine(std::string *pRunLine)
192196
const std::string cmd = sm[2];
193197

194198
// start with the prefix specified on cmd-line
195-
TStringList execList = prefixCmd_;
199+
TStringList execList = tp_.prefixCmd;
196200

197201
if (boost::regex_match(cmd, sm, reLineRunExec_))
198202
// ["cmd", "arg1", "arg2", ...]
@@ -202,7 +206,7 @@ void DockerFileTransformer::transformRunLine(std::string *pRunLine)
202206
appendShellExec(&execList, cmd);
203207

204208
newRunLine += runCmdFromExecList(execList);
205-
if (verbose_) {
209+
if (tp_.verbose) {
206210
// diagnostic output printed with --verbose
207211
std::cerr << prog_name << " <<< " << *pRunLine << std::endl;
208212
std::cerr << prog_name << " >>> " << newRunLine << std::endl;
@@ -365,17 +369,18 @@ int main(int argc, char *argv[])
365369
return 0;
366370
}
367371

368-
const bool verbose = !!vm.count("verbose");
372+
// read cmd-line flags
373+
TransformerProps tp;
374+
tp.verbose = !!vm.count("verbose");
369375

370376
// read the prefix command
371-
TStringList prefixCmd;
372-
if (!readListFromValMap(&prefixCmd, vm, "prefix-cmd")) {
377+
if (!readListFromValMap(&tp.prefixCmd, vm, "prefix-cmd")) {
373378
desc.print(std::cerr);
374379
return 1;
375380
}
376381

377-
// pass cmd-line args to DockerFileTransformer
378-
DockerFileTransformer dft(prefixCmd, verbose);
382+
// create the transformer object
383+
DockerFileTransformer dft(tp);
379384

380385
if (vm.count("in-place"))
381386
// transform Dockerfile in-place

0 commit comments

Comments
 (0)
Please sign in to comment.