Coder Social home page Coder Social logo

nopandacode.applicationenvironment's Introduction

NoPandaCode.ApplicationEnvironment

This is a library with some application helpers.

AppRunner

The AppRunner allows you to run specific apps created by yourself. An app is just a class with the Application Attribute. In your app you can create commands with, optionally, flags and options. A flag is just an argument and a option is almost the same but they can contain a value. (For example.: Flag: "hello_this_is_a_flag", Option: "yourname=paul")

Create an app

Just I said, an is a class with an Application Attribute.

[Application(Name = "TestApplication")] // <--- The Attribute
public class MyApplication
{
    // ...
}

Create a command

A command is a method with a CommandAttrbute. If you not set the name, it will be automaticly take the name from the method.

[Command(Name = "testcommand")]
public void Test()
{
    // ...
}

Add Description

It can be helpful if you add a description to your command. For example, you're creating a console application with some off these apps. It might be useful that the user can see what the command is doing.

[Command(Name = "testcommand", Description = "This command does nothing.")]
public void Test()
{
    // ...
}

Default Command

If you want to only execute the app and not a command you can create a "default command". Just set the Type to CommandType.DefaultCommand.

[Command(Type = CommandType.DefaultCommand)]
public void ThisIsDefault()
{
    // ...
}

Parameters (Flags, Options)

Just I said, you can add flags and options to your command. Just add a string List and a string Dictionary to your method parameters.

[Command(Name = "testcommand", Description = "This command does nothing.")]
public void Test(List<string> flags, Dictionary<string, string> options)
{
    // ...
}

If you only want to get all arguments, then just add a string array.

[Command(Name = "testcommand", Description = "This command does nothing.")]
public void Test(string[] args)
{
    // ...
}

Final: Run the application

Now we have our application with some commands. We only need to run it. Do that:

// 1.
AppRunner.Run<MyApplication>("testcommand", new string[] {"hello", "world=true"});
// 2.
AppRunner.Run(typeof(MyApplication), "testcommand", new string[] {"hello", "world=true"});

// Default Command
AppRunner.Run<MyApplication>(null, new string[] {"hello", "world=true"});

// No Arguments
AppRunner.Run<MyApplication>("testcommand", Array.Empty<string>());

nopandacode.applicationenvironment's People

Contributors

paulschoenau avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.