Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Bug - whitespace in a boost::path option #55

Open
ronen opened this issue Feb 5, 2018 · 0 comments
Open

Bug - whitespace in a boost::path option #55

ronen opened this issue Feb 5, 2018 · 0 comments

Comments

@ronen
Copy link
Contributor

ronen commented Feb 5, 2018

Hi, thanks for the cool library, I'm enjoying using it and look forward to its ongoing development!

I seem to have encountered a bug, though: if the argument to a boost::path option has white space in it, the resulting path only includes the first word. Here's a small example:

#include <boost/filesystem/path.hpp> // using boost 1.66
#include <clara.hpp>                 // using v1.1.1
#include <iostream>
#include <string>

using path = boost::filesystem::path;
using namespace clara;

int main(int argc, char *argv[]) {

  path path_opt;
  std::string string_opt;

  const auto cli = Opt(path_opt, "path")["--path"]("boost path argument") |
                   Opt(string_opt, "string")["--str"]("string argument");
  const auto result = cli.parse(Args(argc, argv));
  if (!result) {
    std::cerr << "Error: " << result.errorMessage() << std::endl;
    exit(1);
  }

  std::cout << "path_opt=" << path_opt << std::endl;
  std::cout << "path(string_opt)=" << path(string_opt) << std::endl;
}

Here's what happens when I compile and run... notice below that the path "with a space" comes out to just "with".

$ c++ --std=c++11 -I. -o bug bug.cpp -lboost_system   # Apple LLVM version 9.0.0 (clang-900.0.39.2)
$ ./bug --path "with a space" --str "with a space"
path_opt="with"
path(string_opt)="with a space"
$

Of course the workaround of using a string opt then creating a path from that is viable, just not nearly as pretty.

It's possible that this isn't a Clara bug per se, but just that boost::path don't have the right construction semantics to work as a Clara Opt. If so that's a bummer -- and a little insidious, since it seems to work fine as long as there's no whitespace. And when/if you do use a path with whitespace there's no warning, just elsewhere in the app you get unexpected behavior because the path isn't what you think it is :)

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

No branches or pull requests

1 participant