Skip to content

Cannot parse "1" #797

@yevheniia-alikberova

Description

@yevheniia-alikberova

E.g. "--KEEP_ALIVE_OPTION=1".

This treats by the parser as no value:
Option 'keep_alive_option" has no value.
Required option 'keep_alive_option' is missing.

public class KeepAliveOptions
    {
        [Option(Required = true)]
        public string KEEP_ALIVE_OPTION { get; set; }
        [Option(Required = true)]
        public string LOGIN_URL { get; set; }
        [Option(Required = true)]
        public string ADVISOR_PASSWORD { get; set; }
        [Option(Required = true)]
        public string COMPANY_NUMBER { get; set; }
        [Option(Required = true)]
        public string OUT_DIR { get; set; }
        [Option(Required = true)]
        public string UserID { get; set; }
        [Option(Required = true)]
        public string Password { get; set; }
    }
public ParserResult<T> Parse<T>(string[] args) where T : IScriptOptions
        {
            Parser parser = new(s =>
            {
                s.CaseSensitive = false;
                s.IgnoreUnknownArguments = true;
                s.HelpWriter = Parser.Default.Settings.HelpWriter;
            });

            var scriptOptions = new List<string>();

            for (int i = 0; i < args.Length; i++)
            {
                string option = $"--{args[i].TrimStart('/')}";

                scriptOptions.Add(option);
            }

            return parser.ParseArguments<T>(scriptOptions);
        }
var result = Parse<KeepAliveOptions>(args)
                    .WithParsed(keepAliveOptions => options = keepAliveOptions)

Tried to change KEEP_ALIVE_OPTION type to int, it doesn't change anything

Fiddle: https://dotnetfiddle.net/vbujQc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions