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

leave deprecated option flags out of help text without break tools #331

Merged
merged 2 commits into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontends/common/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ CompilerOptions::CompilerOptions() : Util::Options(defaultMessage) {
[this](const char*) {
langVersion = CompilerOptions::FrontendVersion::P4_14;
return true; },
"[Deprecated] Specify language version to compile");
"[Deprecated] Specify language version to compile", true);
registerOption("--p4-16", nullptr,
[this](const char*) {
langVersion = CompilerOptions::FrontendVersion::P4_16;
return true; },
"[Deprecated] Specify language version to compile");
"[Deprecated] Specify language version to compile", true);
registerOption("--p4v", "{14|16}",
[this](const char* arg) {
if (!strcmp(arg, "1.0") || !strcmp(arg, "14")) {
Expand Down
8 changes: 6 additions & 2 deletions lib/options.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2013-present Barefoot Networks, Inc.
Copyright 2013-present Barefoot Networks, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,8 @@ limitations under the License.
#include "options.h"

void Util::Options::registerOption(const char* option, const char* argName,
OptionProcessor processor, const char* description) {
OptionProcessor processor, const char* description,
bool hide) {
if (option == nullptr || processor == nullptr || description == nullptr)
throw std::logic_error("Null argument to registerOption");
if (strlen(option) <= 1)
Expand All @@ -29,6 +30,7 @@ void Util::Options::registerOption(const char* option, const char* argName,
o->argName = argName;
o->processor = processor;
o->description = description;
o->hide = hide;
auto opt = get(options, option);
if (opt != nullptr)
throw std::logic_error(std::string("Option already registered: ") + option);
Expand Down Expand Up @@ -100,6 +102,8 @@ void Util::Options::usage() {
for (auto o : optionOrder) {
auto option = get(options, o);
size_t len = strlen(o);
if (option->hide)
continue;
*outStream << option->option;
if (option->argName != nullptr) {
*outStream << " " << option->argName;
Expand Down
6 changes: 4 additions & 2 deletions lib/options.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2013-present Barefoot Networks, Inc.
Copyright 2013-present Barefoot Networks, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,6 +41,7 @@ class Options {
const char* argName; // nullptr if argument is not required
const char* description;
OptionProcessor processor;
bool hide; // is true to hide option from help message
};
const char* binaryName;
cstring message;
Expand All @@ -59,7 +60,8 @@ class Options {
const char* argName, // name of option argument;
// nullptr if no argument expected
OptionProcessor processor, // function to execute when option matches
const char* description); // option help message
const char* description, // option help message
bool hide = false); // hide option from --help message

explicit Options(cstring message) : binaryName(nullptr), message(message) {}

Expand Down