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] Defining Options in Base Class and using them in derived class

alexhughes05 opened this issue · comments

In my application I have a base class that defines several different options which represents commands I want to use in several different derived classes. However, when I insert the command-line arguments and run my application, these options are null. Their values never get set. This is interesting because options I define in the derived class work fine, their values are propagated as intended. It's only when I try to use an option from a base class in a derived class that I have issues. Is this something that is supposed to happen?

It sounds like you are describing the functionality shown in the Subcommands using inheritance sample. Have you cross referenced your implementation with that of the sample?

If you're still having issues, provide a condensed example of your implementation along with the arguments and output that exhibit the described unexpected behavior. Without context, it's hard to say, but it sounds like you're dealing with a nuance between shared functionality (eg using derivation to provide a commonly used option such as --verbosity to multiple otherwise-unrelated commands, with each command having its own unique instance of that option) and shared state (accessing the value assigned to a parent command's option from inside a subcommand).

// You can use this pattern when the parent command may have options or methods you want to
// use from sub-commands.
// This will automatically be set before OnExecute is invoked
private Git Parent { get; set; }

var args = Parent.CreateArgs();
args.Add("add");

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project.

Closing due to inactivity.
If you are looking at this issue in the future and think it should be reopened, please make a commented here and mention natemcmaster so he sees the notification.