Skip to the content.

UltraMapper.Commandline

Build status NuGet

A commandline parser supporting direct method calls taking as input an unlimited number of primitive and complex-type parameters

What is UltraMapper.CommandLine?

UltraMapper.CommandLine is a .NET command line parser: a tool that parse (analyze and interpret) your command line text and map (trasform) it into strongly-typed objects.

UltraMapper.CommandLine drastically simplifies your code:

UltraMapper.CommandLine is powered by UltraMapper, a powerful .NET mapper!

Game changing features!

Getting started by example

Ok this will have some complexity to it, but i want to impress you!

The following example shows how to call the AddToDatabase method from commandline, passing as input a string representation of the well structured complex-type CustomerInfo, which the method AddToDatabase takes as input.

class Program
{
    static void Main( string[] args )
    {
        //--add ("John Smith" 26 account=(number=AC2903X balance=3500.00 creditcards=[(CRD01 1000.00) (CRD02 2000.00)]))
        CommandLine.Instance.Parse<CommandLineSupportedCommands>( args );
    }

    public class CommandLineSupportedCommands
    {
        [Option( Name = "add", HelpText = "Adds new customer to db" )]
        public void AddToDatabase( CustomerInfo customer )
        {
            Assert.IsTrue( customer.Name == "John Smith" );
            Assert.IsTrue( customer.Age == 26 );
            Assert.IsTrue( customer.Account.AccountNumber == "AC2903X" );
            Assert.IsTrue( customer.Account.Balance == 3500 );
            Assert.IsTrue( customer.Account.CreditCards[ 0 ].CardNumber == "CRD01" );
            Assert.IsTrue( customer.Account.CreditCards[ 0 ].MonthlyLimit == 1000 );
            Assert.IsTrue( customer.Account.CreditCards[ 1 ].CardNumber == "CRD02" );
            Assert.IsTrue( customer.Account.CreditCards[ 1 ].MonthlyLimit == 2000 );

            Console.WriteLine( "New customer inserted!" );
        }
    }

    public class CustomerInfo
    {
        public class BankAccountInfo
        {
            public class CreditCardInfo
            {
                public string CardNumber { get; set; }
                public double MonthlyLimit { get; set; }
            }

            [Option( Name = "number" )]
            public string AccountNumber { get; set; }
            public double Balance { get; set; }

            public List<CreditCardInfo> CreditCards { get; set; }
        }

        public string Name { get; set; }
        public int Age { get; set; }

        public BankAccountInfo Account { get; set; }
    }
}

The above example shows a few basic features to start with:

There are a couple more things and a few remarks you should know about UltraMapper.CommandLine
Check out the wiki for more information

ANY FEEDBACK IS WELCOME