code first, ask questions later

NetBash Updated – Formatting Helpers Added

NetBash (drop in command line for asp.net web applications) was first released late last year with little to no response from the community. No big deal – I built it to scratch my own itch so it was at least going to be useful to me. Then, like clockwork I go on holidays for a week and a bit and it is featured on Asp.net and tweeted by close to 100 people. I have used the past few days to catch up with the bugs people have found (thanks heaps to those who forked and fixed bugs themselves) and get a new release out on NuGet.

Bug Fixes

  • NetBash is now compatible with older versions of JQuery (1.5 at least). This was causing some issues with people using a fresh file – new project mvc app to test it out.
  • Console now auto scrolls to bottom when opened.
  • Now more compatible with older versions of IE.

Formatting Extensions

A couple of classes have been included in the NetBash.Formatting namespace to help make the output of your commands a bit prettier. The most useful is the TableExtensions class contributed by Damian Karzon. This class includes a couple of extension methods on IEnumerable<T> that take a list of objects and using reflection output them into a nice consoley table. Here is an example:

public string Process(string[] args)
{
    var tempData = new List<GridData>
    {
        new GridData
        {
            RowId = 1,
            SomeName = "NUMBER1",
            Longtext = "12345678901234567890",
            SomeDate = DateTime.Today
        },
        new GridData
        {
            RowId = 2,
            SomeName = "sup bro",
            Longtext = "I AM THE GREATEST",
            SomeDate = DateTime.Now.AddDays(21)
        },
        new GridData
        {
            RowId = 5,
            SomeName = "GridCommand",
            Longtext = "longish",
            SomeDate = DateTime.Now.AddDays(-3)
        }
    };

    return tempData.ToConsoleTable();
}

Output:

gridyo

Pretty neat I think. It works with most things I’ve thrown at it including anonymous classes but not dynamic.

The other class is called SparkExtensions. This class is a C# port of this cool little shell script. The Spark() methods are extension methods on various IEnumerable collections (int, decimal, string, etc) they take the list and turn it into a cool little spark line graph similar to this: ▁▂▃▅▂▇. Here is a basic example:

public string Process(string[] args)
{
    var list = new List<int>() { 5, 7, 3, 8, 9, 2, 12, 7, 6 };

    return list.Spark();
}

Hopefully these additions make building commands a little more painless. If you are using NetBash or better still have built some open source commands I'd love to hear from you. NetBash source can be found on Github and downloaded using NuGet.

blog comments powered by Disqus