PowerShell / DSC

This repo is for the DSC v3 project
MIT License
200 stars 29 forks source link

Added adapter filter #377

Closed anmenaga closed 6 months ago

anmenaga commented 6 months ago

PR Summary

Fix #274 Fix #368

1) Removed duplicates from path list, so that same resources would not be processed multiple times; 2) re-enabled WMI provider 3) Added filter for adapters, so that in default scenarios 'List' operation on adapters is not executed, therefore reducing time.

Usage: dsc.exe resource list [OPTIONS] [RESOURCE_NAME]

Arguments:
  [RESOURCE_NAME]  Optional filter to apply to the list of resources

Options:
  -a, --adapter <ADAPTER_NAME>     Adapter filter to limit the resource search
  -d, --description <DESCRIPTION>  Description keyword to search for in the resource description
  -t, --tags <TAGS>                Tag to search for in the resource tags
  -f, --format <FORMAT>            The output format to use [possible values: json, pretty-json, yaml]
  -h, --help                       Print help

Examples:

  1. dsc resource list same as dsc resource list * - show all native resources, adapters, but not adapter-based resources (fastest);
  2. dsc resource list *Microsoft* - same as previous but also apply *Microsoft* filter;
  3. dsc resource list * -a * - show all adapter-based resources;
  4. dsc resource list * -a *PowerShell* - show all resources of adapters that match *PowerShell* filter
  5. dsc resource list *MSFT_PackageManagement* *PowerShell* - same as previous but also apply *MSFT_PackageManagement* filter to resource types;
anmenaga commented 6 months ago

Added tests.

SteveL-MSFT commented 6 months ago

After trying out your branch, we should discuss some user experience options:

For docs, we should make the examples use wildcards in single quotes:

dsc resource list '*os*'

As on non-Windows, the shell will try to glob the wildcard and pass found files to the command causing it to fail.

cc @mgreenegit, @michaeltlombardi

anmenaga commented 6 months ago

My thoughts: 1.

  • Currently, to use an adapter, you have to specify * or some resource name. I would prefer something like dsc resource list --adapter Microsoft.DSC/PowerShell and have it show all the PowerShell resources

It is shorter to type * for type filter than --adapter of the named parameter. I'd leave it as is.

2.

  • When an adapter is specified, should the list ONLY contain resources for that adapter. I would think this would be expected unless you use a wildcard for the adapter, of course.

I agree with this; it is more intuitive than current behavior.

mgreenegit commented 6 months ago

Get-dscresource allows the user to specify a module or individual resource. The operation is faster when it is scoped. That might be worth considering as well.

SteveL-MSFT commented 6 months ago

My thoughts: 1.

  • Currently, to use an adapter, you have to specify * or some resource name. I would prefer something like dsc resource list --adapter Microsoft.DSC/PowerShell and have it show all the PowerShell resources

It is shorter to type * for type filter than --adapter of the named parameter. I'd leave it as is.

We would have a -a short name for --adapter. Particularly on Unix where you have to single-quote the wildcard so that it doesn't get globbed, my preference is to have adapter be a named arg and not require *.

anmenaga commented 6 months ago
  • Currently, to use an adapter, you have to specify * or some resource name. I would prefer something like dsc resource list --adapter Microsoft.DSC/PowerShell and have it show all the PowerShell resources
  • When an adapter is specified, should the list ONLY contain resources for that adapter. I would think this would be expected unless you use a wildcard for the adapter, of course.

Updated code and PR description for both points.