Giter Site home page Giter Site logo

command-liner's Introduction

Command Liner

Logo Logo Logo

A handy header-only library that helps you to make your libraries to command-line applications.

Example usage

#include "src/Option.hpp"
#include "src/CommandHandler.hpp"
#include <iostream>

auto getArgsString(std::vector<std::string> const& args) -> std::string {
    std::string argsString;

    for (auto const& arg : args) {
        argsString += arg + " ";
    }

    return argsString;
}

auto main(int argc, char* argv[]) -> int {
    const Option myOption{
            .id = 0,
            .verboseName = "--myCommand",
            .quickName = "-m",
            .description = "The description of my command.",
            .function = [](std::vector<std::string> const& args) {
                std::cout << "Here can I execute the function for my command\n"
                          << "with the arguments: "
                          << std::endl;

                return getArgsString(args);
            }};

    // Program arguments as a vector of strings.
    const auto args = std::vector<std::string>(argv, argv + argc);

    // CommandHandler
    CommandHandler commandHandler(args);
    commandHandler.add(myOption);
    commandHandler.execute();

    return 0;
}

Pre defined Options

The following Options are defined by default.

Option Name (Verbose | Quick) Required Arguments
Quit --quit, -q โ€”
Version --version, -v โ€”
Verbose --verbose, -V
Help --help, -h Used the description off all given commands

Multi & combined option execution

All options there are defined as Commands and you use in a console command, will be executed in order or together if there combined action defined.

Up to 56 self defined Commands

Inside all commands toggle a bit of an unsigned integer with 64 bits (8 byte), the last byte is reserved for pre-defined commands. So you can define up to 56 Commands and for all of these combined actions if you want. The list of arguments is untouched of any restrictions.

Alias Commands

You can define alias command for an existing one to improve the user experience of your CLI Tool.

Command Line Syntax

The syntax of the command line is as follows:

$ ./myProgram [options] [arguments]

command-liner's People

Contributors

codebycr 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.