natemcmaster / CommandLineUtils

Command line parsing and utilities for .NET

Home Page:https://natemcmaster.github.io/CommandLineUtils/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] How to mark options and arguments with custom attributes

SteveBenz opened this issue · comments

I'm converting an application with a bespoke command line parser to this library. One of the things that application does is pack up the command line it was given and send it to appinsights telemetry. But, it doesn't pack up everything because some of the arguments could contain secrets or PII.

I've been hunting for a way to hang an attribute or something to specify whether or not the option can go up. I can think of a way to do it, but I wonder if there's a better way.

My scheme is to create a custom validator that always returns success. I can query for the presence of that validator from CommandOptions.Validators as I'm packing up the options for telemetry. It works, but it feels like feature-abuse.

This library is extensible enough that you can build your own customer attributes and add them by using the custom conventions API.

https://github.com/natemcmaster/CommandLineUtils/tree/main/docs/samples/custom-conventions
https://github.com/natemcmaster/CommandLineUtils/tree/main/docs/samples/custom-attribute

It's really up to you whether you want to couple telemetry to CLI parsing.

Hope that helps.