From df0c0880589eb174eba3b9866be76fe4d06dc703 Mon Sep 17 00:00:00 2001
From: Han Wang <han.wang@barefootnetworks.com>
Date: Thu, 23 Feb 2017 17:39:03 -0800
Subject: [PATCH] leave deprecated option flags out of help text without break
 existing tools

---
 frontends/common/options.cpp | 4 ++--
 lib/options.cpp              | 8 ++++++--
 lib/options.h                | 6 ++++--
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/frontends/common/options.cpp b/frontends/common/options.cpp
index 7b55d17acc1..36b90c3045f 100644
--- a/frontends/common/options.cpp
+++ b/frontends/common/options.cpp
@@ -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")) {
diff --git a/lib/options.cpp b/lib/options.cpp
index 49e246ca51c..93c32c62451 100644
--- a/lib/options.cpp
+++ b/lib/options.cpp
@@ -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.
@@ -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)
@@ -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);
@@ -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;
diff --git a/lib/options.h b/lib/options.h
index 8cfd47e54b4..fc4d6ccfec1 100644
--- a/lib/options.h
+++ b/lib/options.h
@@ -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.
@@ -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;
@@ -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) {}