hemprasad / gflags

Automatically exported from code.google.com/p/gflags
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Add flag alias feature to rename old flag smoothly #65

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
For a long term project, there exist some misnamed flags, such as missing 
currect prefix, or module name changed. if we changed the name, the 
code/running system will be broken.

Consider introduce a alias mechanism to resolve this problem.

// Modified flag with new correct name
DEFINE_int32(xfs_master_port, 8000, "some bool value");

// Compatible old name for xfs_master_port
DEFINE_int32_alias(master_port, xfs_master_port);

Run:
$ ./gflags_test --xfs_master_port=2 --help
  Flags from thirdparty/gflags/gflags_test.cpp:
    --master_port (compatible old name of 'xfs_master_port')
      type: int32 default: 8000 currently: 2
    --xfs_master_port (some bool value) type: int32
      default: 8000 currently: 2

I've implemented this feature, see the attach.

Original issue reported on code.google.com by chen3feng on 28 Jan 2013 at 1:22

Attachments:

GoogleCodeExporter commented 9 years ago
This works, but no deprecated warning because of this bug of gcc, clang hs no 
this problem.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56130

And a warning message should be printed when set the flag from command 
line/flagfile.
To do this, more code should be modified, so I didn't do it.

Original comment by chen3feng on 29 Jan 2013 at 10:25

GoogleCodeExporter commented 9 years ago
Sorry for not replying earlier. I think this can be a useful addition. Given 
that I myself end up being sometime indecisive about the actual flag name, it 
could even be interesting to allow aliases without deprecation warning. 
Moreover, I think these aliases should only be aliases for the command-line, 
but not actual global variable references in the code. If you want to postpone 
renaming the variables in the code, you can still define a reference yourself 
such as

  DEFINE_int32(xfs_master_port, 8000, "some bool value");
  int32 &FLAGS_master_port = FLAGS_xfs_master_port;

with suitable deprecation notice and so forth. This, however, is already 
project specific and I would not make it part of the gflags library API. Most 
developers would at this point search & replace FLAGS_master_port by 
FLAGS_xfs_master_port.

To still allow the use of --master_port as an alternative to --xfs_master_port, 
there could be the possibility to add such alternative strings to the existing 
flag object. For example using a macro such as:

  DEFINE_alias(xfs_master_port, master_port);

This would fit better into the existing API, does not require per-type macros, 
and not introduce additional C++ objects for the same flag value (references). 
Moreover, the help output can consider to format these alternatives along the 
actual primary command-line flag use.

Original comment by andreas....@gmail.com on 20 Mar 2014 at 3:22