Skip to content

Commit 400b44e

Browse files
committed
Tune: Add support for specifying visual studio version -vs flag
1 parent efb780b commit 400b44e

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

SolutionProjectModel/cppexec/cppexec.cpp

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ class CommandLineArguments : public ReflectClassT<CommandLineArguments>
1919
{
2020
public:
2121
CommandLineArguments():
22-
_local(false)
22+
_local(false),
23+
_vs(0)
2324
{
2425

2526
}
2627

2728
REFLECTABLE(CommandLineArguments,
28-
(bool)local
29+
(bool)local,
30+
(int)vs
2931
);
3032
};
3133

@@ -95,7 +97,15 @@ int _wmain(int argc, wchar_t** argv)
9597
continue;
9698
}
9799

98-
int findex = type.GetFieldIndex(CW2A(arg+1));
100+
string cmdarg(CW2A(arg + 1));
101+
102+
if( cmdarg == "?" || cmdarg == "h")
103+
{
104+
scriptToRun.clear();
105+
break;
106+
}
107+
108+
int findex = type.GetFieldIndex(cmdarg.c_str());
99109
if(findex < 0 )
100110
continue;
101111

@@ -120,7 +130,9 @@ int _wmain(int argc, wchar_t** argv)
120130
{
121131
printf("Usage: %S [options] <.cpp script to run>\r\n", exePath.filename().c_str());
122132
printf("where options could be:\r\n");
123-
printf(" -local - Keep generated project locally.\r\n");
133+
printf("\r\n");
134+
printf(" -local - Keep generated project next to script.\r\n");
135+
printf(" -vs <version> - use specific Visual studio (2019, 2017...)\r\n");
124136
return -2;
125137
}
126138

@@ -228,9 +240,22 @@ int _wmain(int argc, wchar_t** argv)
228240
}
229241
CoUninitialize();
230242

231-
auto it = max_element(instances.begin(), instances.end(), [](auto e1, auto e2) { return e1.version < e2.version; });
232-
if (it == instances.end())
233-
throw exception("No Visual Studio installation found");
243+
vector<VisualStudioInfo>::iterator it;
244+
245+
if(cmdargs.vs != 0)
246+
{
247+
it = find_if(instances.begin(), instances.end(), [&](auto vsinfo) { return vsinfo.version == cmdargs.vs; });
248+
249+
if (it == instances.end())
250+
throwFormat("Visual studio %d was not found on this machine", cmdargs.vs);
251+
}
252+
else
253+
{
254+
it = max_element(instances.begin(), instances.end(), [](auto e1, auto e2) { return e1.version < e2.version; });
255+
256+
if (it == instances.end())
257+
throw exception("No Visual Studio installation found");
258+
}
234259

235260
auto devenv = path(it->InstallPath).append("Common7\\IDE\\devenv.com");
236261

0 commit comments

Comments
 (0)