Skip to content

Argument values starting with non-word-characters are treated as operands #54

Closed
@montgomerybc

Description

@montgomerybc

If an Argument's value start with (e.g.) a period or backslash, like a path would, the value is not parsed correctly.

Example:

using System;
using System.Linq;
using Utility.CommandLine;

namespace Foo
{
    class Program
    {
        [Argument('f', "folder")]
        private static string Folder { get; set; }

        [Operands]
        private static string[] Operands { get; set; }

        static void Main(string[] args)
        {
            Arguments.Populate();

            Console.WriteLine($"Folder='{Folder}'");
            Console.WriteLine($"Operands='{String.Join(';', Operands.Skip(1))}'");
        }
    }
}
PM> .\foo.exe
Folder=''
Operands=''

PM> .\foo.exe -f
Folder=''
Operands=''

PM> .\foo.exe -f a.txt
Folder='a.txt'
Operands=''

PM> .\foo.exe -f .\a.txt
Folder=''
Operands='.\a.txt'

PM> .\foo.exe -f ..\a.txt
Folder=''
Operands='..\a.txt'

PM> .\foo.exe -f \path\to\a.txt
Folder=''
Operands='\path\to\a.txt'

PM> .\foo.exe -f \\server\path\to\a.txt
Folder=''
Operands='\\server\path\to\a.txt'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions