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

improve: GpCommandLineParser: allow to restrict for assign published properties only #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ashumkin
Copy link

Sometimes a target class can have a public property of a custom
enumeration type which is set from a string value from a command line.
E.g.
type
TLogLevel = (llTrace, llDebug, ...

TCommandLine = class
private
  FLogLevel: TLogLevel
public
  property LogLevel: TLogLevel read FLogLevel write FLogLevel;

  [CLPLongName('log-level')]
  property LogLevelAsStr: string read GetLogLevelAsStr write SetLogLevelAsStr;
end;

In this case TGpCommandLineParser raises the SUnsupportedPropertyType
exception for LogLevel property as it supports Integer, String and
Boolean types only.

Let's fix it by adding opPublishedPropertiesOnly option to tell a parser
to respect published properties only.
So, TCommandLine will appear to be defined as the following

TCommandLine = class
private
  FLogLevel: TLogLevel
public
  property LogLevel: TLogLevel read FLogLevel write FLogLevel;
published
  [CLPLongName('log-level')]
  property LogLevelAsStr: string read GetLogLevelAsStr write SetLogLevelAsStr;
end;

…properties only

Sometimes a target class can have a public property of a custom
enumeration type which is set from a string value from a command line.
E.g.
  type
    TLogLevel = (llTrace, llDebug, ...

    TCommandLine = class
    private
      FLogLevel: TLogLevel
    public
      property LogLevel: TLogLevel read FLogLevel write FLogLevel;

      [CLPLongName('log-level')]
      property LogLevelAsStr: string read GetLogLevelAsStr write SetLogLevelAsStr;
    end;

In this case TGpCommandLineParser raises the SUnsupportedPropertyType
exception for LogLevel property as it supports Integer, String and
Boolean types only.

Let's fix it by adding opPublishedPropertiesOnly option to tell a parser
to respect published properties only.
So, TCommandLine will appear to be defined as the following

    TCommandLine = class
    private
      FLogLevel: TLogLevel
    public
      property LogLevel: TLogLevel read FLogLevel write FLogLevel;
    published
      [CLPLongName('log-level')]
      property LogLevelAsStr: string read GetLogLevelAsStr write SetLogLevelAsStr;
    end;
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 this pull request may close these issues.

1 participant