Skip to content
This repository

Drop in console interface for running commands in web applications

branch: master

Merge pull request #25 from andyedinborough/patch-1

Don't die because of missing assemblies
latest commit 7593058a1b
Luke Lowrey authored November 01, 2012
Octocat-spinner-32 NetBash.Sample changed version January 14, 2012
Octocat-spinner-32 NetBash Don't die because of missing assemblies November 01, 2012
Octocat-spinner-32 packages removed json.net dependency December 12, 2011
Octocat-spinner-32 .gitignore prototype stuff December 08, 2011
Octocat-spinner-32 NetBash.nupkg added nuget package January 15, 2012
Octocat-spinner-32 NetBash.sln move solution file December 08, 2011
Octocat-spinner-32 README.md Update README.md January 15, 2012
Octocat-spinner-32 netbash.nuspec nuget stuff December 11, 2011
README.md

NetBash is a drop in (think mvc mini profiler) command line for your web app.

Download from NuGet - PM> Install-Package NetBash

Set up

On application start call NetBash.Init() to initilize the routes. You can optionally set the Authorize action, this action is run to determine whether to show the console.

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);

    NetBash.Init();
    NetBash.Settings.Authorize = (request) =>
        {
            return request.IsLocal;
        };
}

You also need to add the render includes code somewhere on your page (_Layout.cshtml is proabably easiest).

@NetBash.RenderIncludes()

Usage

NetBash commands are sent using this format - "[command name] [arg1] [arg2] etc". You can see which commands are currently loaded by typing "help". There are also a few keyboard shortcuts (which can be viewed with "shortcuts" the most useful being "`" to open and focust the console. [todo link to blog post]

Creating a Command

NetBash will look for any implementation of the interface IWebCommand with a WebCommand attribute on first request. To create a command simply implement IWebCommand and add the WebCommand Attribtue.

[WebCommand("length", "Returns number of characters in given arguments")]
public class LengthCommand : IWebCommand
{
    public bool ReturnHtml
    {
        get { return false; }
    }

    public string Process(string[] args)
    {
        return string.Join(" ", args).Length.ToString();
    }
}

This silly example just returns the number of chars in the arguments you pass. The first parameter of WebCommand is the name you use to invoke the command, the second is the description that shows up in help.

Commands

Over on the wiki is a list of commands people have made - https://github.com/lukencode/NetBash/wiki/Commands

Something went wrong with that request. Please try again.