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

short arg unable to accept argument. #429

Open
vipcxj opened this issue Apr 23, 2024 · 0 comments
Open

short arg unable to accept argument. #429

vipcxj opened this issue Apr 23, 2024 · 0 comments

Comments

@vipcxj
Copy link

vipcxj commented Apr 23, 2024

            cxxopts::Options opts("ai-server", "ai server");
            opts.add_options("general")
                ("h,help", "Print usage", cxxopts::value<std::vector<std::string>>()->implicit_value(""))
                ("groups", "Print all groups")
                ("print", "Print configure values of special group. Empty group means all group.", cxxopts::value<std::string>()->implicit_value(""));
            opts.add_options("cfgo")
                ("s,signal_url", "The url of signal server of conference.go", cxxopts::value<std::string>()->default_value(get_default_opt_from_env("SR_CFGO_SIGNAL_URL", "")))
                ("appsink_drop", "Drop old buffers when the buffer queue is filled", cxxopts::value<bool>()->default_value(get_default_opt_from_env("SR_CFGO_APPSINK_DROP", "false")))
                ("appsink_max_buffers", "Maximum amount of buffers in the queue (0 = unlimited).", cxxopts::value<std::uint32_t>()->default_value(get_default_opt_from_env("SR_CFGO_APPSINK_MAX_BUFFERS", "0")))
                ("appsink_max_bytes", "Maximum amount of bytes in the queue (0 = unlimited)", cxxopts::value<std::uint64_t>()->default_value(get_default_opt_from_env("SR_CFGO_APPSINK_MAX_BYTES", "0")))
                ("appsink_max_time", "Maximum total duration of data in the queue (0 = unlimited)", cxxopts::value<std::uint64_t>()->default_value(get_default_opt_from_env("SR_CFGO_APPSINK_MAX_TIME", "0")));>implicit_value(""));
            auto result = opts.parse(argc, argv);
            if (result.count("help"))
            {
                auto & groups = result["help"].as<std::vector<std::string>>();
                for (auto && g : groups)
                {
                    std::cout << "group: " << g << std::endl;
                }
                if (groups.size() == 1 && groups[0].empty())
                {
                    std::cout << opts.help(opts.groups()) << std::endl;
                }
                else
                {
                    std::cout << opts.help(groups) << std::endl;
                }
                exit(0);
            }

main --help=general,cfgo print:

group: general
group: cfgo
ai server
Usage:
  ai-server [OPTION...]

 general options:
  -h, --help [=arg(=)]   Print usage
      --groups           Print all groups
      --print [=arg(=)]  Print configure values of special group. Empty 
                         group means all group.

 cfgo options:
  -s, --signal_url arg          The url of signal server of conference.go 
                                (default: "")
      --appsink_drop            Drop old buffers when the buffer queue is 
                                filled
      --appsink_max_buffers arg
                                Maximum amount of buffers in the queue (0 = 
                                unlimited). (default: 0)
      --appsink_max_bytes arg   Maximum amount of bytes in the queue (0 = 
                                unlimited) (default: 0)
      --appsink_max_time arg    Maximum total duration of data in the queue 
                                (0 = unlimited) (default: 0)

main -hgeneral,cfgo print:

terminate called after throwing an instance of 'cxxopts::exceptions::no_such_option'
  what():  Option 'g' does not exist
Aborted (core dumped)

main -h general,cfgo print

group: 
ai server
Usage:
  ai-server [OPTION...]
  ...

cxxopts think no argument is put to h opt. so goup is implicit_value {""}

By the way, how to make implicit_value of std::vectorstd::string as empty vector? "" means a vector with one empty string element, it's too strange.

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