[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not set string value #38

Open
hdhog opened this issue Oct 31, 2019 · 0 comments
Open

not set string value #38

hdhog opened this issue Oct 31, 2019 · 0 comments

Comments

@hdhog
Copy link
hdhog commented Oct 31, 2019

sample code:

#include <iostream>
#include <filesystem>
#include <vector>
#include <clipp.h>

#define VERSION "0.0.0.0"
class app {
public:
    app(int argc, const char** argv) {
        args.assign(argv, argv + argc);
    }

    int exec() {
        try {
            cli =
                ("General:" %
                     ((clipp::option("-c", "--config") & clipp::value("file name", config_file)) %
                          "config file",
                      (clipp::option("-h", "--help").set(f_help)) % "help message",
                      (clipp::option("-v", "--version").set(f_version)) % "show version") ,
                 "Commands:" %
                     ("service" %
                      (clipp::command("service") % "service controll",
                       (((clipp::option("-I", "--install").set(cmd_install)) % "install service") |
                        ((clipp::option("-R", "--remove").set(cmd_remove)) % "remove service")))));

            auto parse_res = clipp::parse(args, cli);

            if(!parse_res.any_error()) {
                show_help();
                return 1;
            }

            if(f_help) {
                show_help();
                return 0;
            }

            if(f_version) {
                std::cout << VERSION << std::endl;
                return 0;
            }

            std::filesystem::path fname(config_file);
            std::cout << "cfg: " << config_file << "\n";
            std::cout << fname.is_absolute() << "\n";
            std::cout << fname << "\n";

            if(cmd_install) {
                //install
                return 0;
            }

            if(cmd_remove) {
                //remove
                return 0;
            }
        } catch(std::exception& rcError) {
            std::cerr << rcError.what() << std::endl;
            return 1;
        }
        return 0;
    }
    void show_help() {
        auto fmt = clipp::doc_formatting {}
                       .first_column(4)
                       .doc_column(36)
                       .merge_alternative_flags_with_common_prefix(true);

        std::cout << clipp::make_man_page(cli, "server", fmt)
                         .prepend_section("AUTHORS", "\tauthor")

                         .prepend_section("DESCRIPTION", "\tThe App")
                  << '\n';
    }

private:
    std::vector<std::string> args;
    clipp::group cli;
    bool f_help = false;
    bool f_version = false;
    bool cmd_install = false;
    bool cmd_remove = false;
    std::string config_file;
};

int main(int argc, const char* argv[]) {	
    app app_instance(argc, argv);
    return app_instance.exec();
}

flag output:

 .\cpp_clipp.exe -c config.toml

DESCRIPTION
        The App

AUTHORS
        author

SYNOPSIS
    server [-c <file name>] [-h] [-v] service [-(I|R)]

OPTIONS
    General:
        -c, --config <file name>    config file
        -h, --help                  help message
        -v, --version               show version

    Commands:
        service                     service controll
        -I, --install               install service
        -R, --remove                remove service

Output

.\cpp_clipp.exe -c config.toml
cfg:
0
""

variable config_file is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant