Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass arguments to runner in dotnet new templates #1658

Closed
heaths opened this issue Feb 25, 2021 · 6 comments · Fixed by #2338
Closed

Pass arguments to runner in dotnet new templates #1658

heaths opened this issue Feb 25, 2021 · 6 comments · Fixed by #2338
Milestone

Comments

@heaths
Copy link

heaths commented Feb 25, 2021

Templates for dotnet new were added for #1028 but don't use any passed arguments for the runner. With the global tool deprecated, this world provide a convenient way of customizing frameworks, reports, etc. from a console.

So instead of:

public static void Main(string[] args)
{
    var summary = BenchmarkRunner.Run<$(BenchmarkName)>();
}

The templates could use:

public static void Main(string[] args) 
{
    BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
@heaths
Copy link
Author

heaths commented Feb 25, 2021

Happy to, but in testing this out, I found it would otherwise force passing something like --filter *Benchmarks* (or whatever non-default benchmark name was used) so I'm trying to find a suitable replacement, i.e. no additional input required so the UX remains consistent. Using BenchmarkSwitcher.FromTypes doesn't change this behavior, such that you're prompted for which benchmarks to run if not otherwise filtered.

Still working on it, but any suggestions?

@heaths
Copy link
Author

heaths commented Feb 25, 2021

Somewhat oddly, BenchmarkSwitcher.RunAll doesn't take args. This almost seems to imply that Run(args) was meant mainly to filter benchmarks, while seemingly all possible options of the old global tool can be passed (I didn't compare completely, but both are long lists of switches and have a lot of recognizable overlap).

@heaths
Copy link
Author

heaths commented Feb 25, 2021

Seems the main culprit is:

var benchmarksToFilter = options.UserProvidedFilters || !askUserForInput

If types were provided explicitly like in the following example that could be used in the template instead, perhaps, by default, the user shouldn't be prompted. Given the seeming intent of passing an explicit list of benchmark types, would you agree?

BenchmarkSwitcher.FromTypes(new[] { typeof(Benchmarks) }).Run(args);

@heaths
Copy link
Author

heaths commented Feb 25, 2021

To clarify, if that was the intent, I can go ahead and fix that problem in the BenchmarkSwitcher as well. I just wanted to make sure that was indeed the intent.

@tmds
Copy link
Member

tmds commented Dec 15, 2021

You could add an overload to Run that allows to set askUserForInput, and set it to false in the template.

Otherwise you'll break anyone that relies on getting this prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants