mtmk edited this page Jul 19, 2011 · 16 revisions


Synoptic - Making Console Applications Easier

This library can be used to make writing .NET console applications easier. Conceptually, you can think of it as routing for the command line. You can specify which methods in your application can be accessed via the command line and synoptic does the rest.

The excellent Mono.Options is used internally to do the command line parsing.

Hello World

Create a console application and just reference synoptic.dll in your project:

    using Synoptic;

    namespace ConsoleApplication1
        class Program
            static void Main(string[] args)
                new CommandRunner().Run(args);

        public class MyCommand
            public void SayHello(string message)
                Console.WriteLine("Hello " +  message);

Compile and run your application and you should see output similar to:

C:> ConsoleApplication1
Usage: ConsoleApplication1 COMMAND ACTION [ARGS]

The available commands are:

C:> ConsoleApplication1 my-command
The available actions for command 'my-command' are:

Congratulations - you have now exposed your first command via the command line! Now you can execute your first command:

C:> ConsoleApplication1 my-command say-hello --message world
Hello world

Some of the advanced synoptic topics are below:

Loading commands from external types
Customizing commands
Customizing actions
Customizing action parameters
Using dependency injection
Global options
Using Console Formatter
Exception handling

Find it on NuGet:

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.