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

Unclear/undocumented value interface. #156

Open
mibli opened this issue May 12, 2022 · 4 comments
Open

Unclear/undocumented value interface. #156

mibli opened this issue May 12, 2022 · 4 comments

Comments

@mibli
Copy link

mibli commented May 12, 2022

So I've found myself quite struggling to figure out how to use the returned code. Perhaps documentation or example with the use cases of the functions should be added:

Use case that didn't work:

constexpr char USAGE[] = R"(i3 geometric window switcher

Usage:
  i3switch (next | prev) [wrap]
  i3switch number <num>
  i3switch (left | up | right | down) [wrap]
  i3switch (-h | --help)
)"

int main(int argc, char *argv) {
  auto args = docopt::docopt(std::string(USAGE), std::vector<std::string>(argv + 1, argv + argc), true, "0.1.0");
  
  int order;
  if (args["number"]) {
    order = args["<num>"].asLong();
  }
  
  direction2d = Direction2d::INVALID;
  for (std::pair<std::string, Direction2d> pair : direction_2d_map) {
    if (args[pair.first]) {
      direction2d = pair.second;
      break;
    }
  }
}

Command: i3 switch right

By instinct I was looking for a common pattern like args["left"] or args["left"].empty() to check if argument was present. I expected that direction2d would be set to first encountered direction, and order to contain the value if number keyword was present.

Turns out it's unclear what empty does, because You have to use asBool. And You can't figure it out unless You dig into the parsing, which shouldn't happend for API... So perhaps in example or in README these should get covered?

@jaredgrubb
Copy link
Member

I'm always open to having some documentation PR's to help improve these and make it clearer! Thanks for the idea!

@mibli
Copy link
Author

mibli commented May 16, 2022

I'm thinking, maybe if options are never empty, maybe using bool(value) on options could throw? This is one way of letting developer know it's not the interface he's looking for.

@jaredgrubb
Copy link
Member

Are you proposing that the current behavior should be tweaked? Or that the documentation should be clarified to match the behavior?

@mibli
Copy link
Author

mibli commented May 20, 2022

I'm thinking both :)

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

2 participants