Git Product home page Git Product logo

fluorine / fluentconsoleapplication Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 51 KB

A library for .NET that uses a fluent interface for building Console Applications

License: MIT License

C# 100.00%
fluent linq fluent-interface csharp library class-library command-line command-line-tool console console-application console-tool prompt application command commandline-interface command-line-app command-line-tools command-line-parser nuget nuget-packages

fluentconsoleapplication's Introduction

Introduction

This library for .NET uses a fluent interface of chained methods for building complete Console Applications. Software Developers often reinvent command-line interfaces for their tools, which is very easy until the application's interface becomes too complex to be modified effectively. This tool is an elegant and quick way to do this and let developers focus of higher tasks.

An application can be used in many ways:

  • Directly from the code, as in the following usage example
  • Called with arguments provided from the console
  • In a Read-Evaluate-Parse Loop (REPL)

Usage example

Defining an application, with all its commands.

var application = FluentConsoleApplication.Create("Calculator", "Application to calculate.")
  .DefineCommand("add", "Add two numbers")
    .WithParameter<int>("X", "First operand")
    .WithParameter<int>("Y", "Second operand")
      .Does(args => Console.WriteLine("Total is " + (args.X + args.Y)))
  .DefineCommand("mult", "Multiply two numbers")
    .WithParameter<double>("X", "First operand")
    .WithParameter<double>("Y", "Second operand")
      .Does(args => Console.WriteLine("Total is " + (args.X * args.Y)));
  .DefineCommand("help")
      .Does(args => Console.WriteLine(args.Application.GetDocumentation()));

Using the application by invoking a command with its required arguments, if any:

application.Run("add 5 2");

Output:

Total is 7

Automatic documentation can also be generated for an Application. This documentation is based on the names, types and descriptions provided when the application was defined.

In this example, the help command generates documentation for the currently running application.

Output:

Calculator: Application to calculate.
 - add [X] [Y] - Add two numbers
 - mult [X] [Y] - Multiply two numbers
 - help

fluentconsoleapplication's People

Contributors

fluorine avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

fluentconsoleapplication's Issues

Add an option to set an output, which should be the Standard output by default

The library should have the ability to directly tell the user that something went wrong, like a bad parameter parsing notice or instructions for usage (in similar cases to those). The user should have the option to set the library's output, which would the be standard console output by default. This will allow users to specify files and streams as outputs.

However, this issue is about adding a parameter to the application, an Action delegate, to specify an output.

Create some user-friendly documentation

The README is good enough for now, but the library may grow with new features and possibilities.

We need a /doc/ folder to add any useful documentation.

For more information about usage, see the unit tests.

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.