Giter Site home page Giter Site logo

n-dub / console_plus_plus Goto Github PK

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

A header-only cross-platform console application framework for writing command line tools easily.

License: Apache License 2.0

C++ 100.00%
console console-application framework cpp17 header-only cross-platform command-line-tool

console_plus_plus's Introduction

Console++

A header-only cross-platform console application framework for writing command line tools easily.

Features

  • Easy to use API:
ConsoleApp app("TestApp"); // create an application
app.Description("Just for testing, does nothing") // set description
    .UsageDesc("testapp [options...]") // usage description
    .Version("v1.0.0") // version
    .CommandLineArgs() // start setting command line arguments
    .AddArg2Hyphens<int>() // add an option --some_int <number>
        .Name("some_int")
        .Required(true)
        .Help("Any integer")
        .Build()
    // ...
    .AddArg2Hyphens<NoType>() // add --help flag
        .Name("help")
        .Help("Print help message")
        .Build()
    .Parse(argc, argv); // parse arguments from argc, argv
// ...
if (app.CommandLineArgs().HasArg("help")) { // if has '--help' option
    app.PrintHelp(true); // print generated help message; true - with header (version, description)
    // Prints this:
    // 
    // TestApp v1.0.0
    // Just for testing, does nothing
    // Usage: testapp [options...]
    // Arguments:
    //     --some_int (required) Any integer
    //     --help     (optional) Print help message
    return 0;
}
if (app.PrintErrors()) { // if some error detected (not all required options passed, etc.)
    app.PrintHelp(false); // print generated help message; false - without header
    // Prints this:
    // 
    // Usage: testapp [options...]
    // Arguments:
    //     --some_int (required) Any integer
    //     --help     (optional) Print help message
    return 0;
}
// get value of an argument
if (int* val = app.CommandLineArgs().GetArg<int>("some_int"); val) {
    app.Log(" - {:<20} = {}", "Some Int", *val);
}
  • Python-like string formatting:
FormatStr("{} + {} = {}", 2, 2, 5);  // 2 + 2 = 5
FormatStr("{2} {0} {1}", 1, 2, 3);   // 3 1 2
FormatStr("A:{:>15.3f}", 2.8888);    // A:          2.889
FormatStr("B:{:>15.1f}", 2.8888);    // B:            2.9
FormatStr("C:{:>15.9f}", 2.8888);    // C:         2.8888

Or with 's' literal operator:

using namespace conpp::literals;
// ...
// operator""s returns conpp::String which is std::string with format() member function.
"{} + {} = {}"s.format(2, 2, 5);
  • Console text coloring (only foreground colors are now supported):
// Change text color with #<color code here>;
// Cross-platform color codes are defined in Color enum.
app.Log("#{};Red#{};Green#{};Blue", Color::Red, Color::Green, Color::Blue);

Results on windows:

Linux (tested with windows subsystem for linux):

Building

Just copy the folder 'conpp' to your project and #include "conpp/conpp.h". A compiler with c++17 support is required.

console_plus_plus's People

Contributors

n-dub avatar

Watchers

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