GithubHelp home page GithubHelp logo

cpcli's Introduction

Cpcli (Beta)

serdepp base command line parser

Example

#include "cpcli/cpcli.hpp"
#include <serdepp/adaptor/nlohmann_json.hpp>
#include <serdepp/adaptor/fmt.hpp>

enum class O {
    one, two, three
};

using namespace cpcli::attribute;
struct Build {
    DERIVE_SERDE(Build, .attributes(help, hook(&Self::execute), about{"build command"})
                 [attributes(abbr{"H"}, full{}, desc{"hello test"}, visible{false}, _value{})]
                 (&Self::hello, "hello")
                 [attributes(abbr{"l"}, full{}, desc{"list test"}, _value{})]
                 (&Self::list,  "list")
                 [attributes(abbr{"i"}, full{}, desc{"list test"}, _value{})]
                 (&Self::ilist,  "ilist")
                 [attributes(abbr{"D"}, full{"Def"}, desc{"CMake Option"}, _value{})]
                 (&Self::define, "define")
                 [attributes(abbr{"d"}, full{"def"}, desc{"CMake Option"}, _value{})]
                 (&Self::DD, "DD")
                 [attributes(abbr{"o"}, full{}, desc("or not"), _value{})]
                 (&Self::oo, "oo")
                 )
    std::string hello;
    std::vector<std::string> list;
    std::vector<int> ilist;
    std::map<std::string, bool> define;
    std::map<std::string, std::string> DD;
    O oo;

    static void execute(cpcli::Command& cmd) {
        auto map = serde::deserialize<Build>(cmd);
    }
};

struct __test {
    DERIVE_SERDE(__test, .attributes(help, hook(&Self::execute), about{"test command"}))
    static void execute(cpcli::Command& cmd) {
        auto map = serde::deserialize<__test>(cmd);
        fmt::print("{}\n", map);
    }
};

struct Test {
    DERIVE_SERDE(Test, .attributes(help, hook(&Self::execute), about{"cpcli test command"})
                 (&Self::build_, "build")
                 (&Self::test, "test"))
    Build build_;
    std::map<std::string, std::string> m;
    __test test;

    static void execute(cpcli::Command &cmd) {
        auto map = serde::deserialize<Test>(cmd);
        fmt::print("{}\n",map);
    }
};

int main(int argc, char *argv[])
{
    cpcli::parse_with_exec<Test>(argc, argv);
    
    return 0;
}

Result

./test -h    
cpcli test command

Usage:
   test [OPTIONS]
   test [OPTIONS] [SUBCOMMAND]

Option:
   -h, --help                       Print usage information.

Command:
   build                            build command      
   test                             test command       

./test build -h
build command

Usage:
   build [OPTIONS]

Option:
   -d, --def <KEY=STRING ...>       CMake Option        
   -D, --Def <KEY=BOOL ...>         CMake Option        
   -h, --help                       Print usage information.
   -i, --ilist <=INTEGER ...>       list test           
   -l, --list <=STRING ...>         list test           
   -o, --oo <one | two | three>     or not              

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.