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

Add flag alias feature to rename old flag smoothly #65

Open
GoogleCodeExporter opened this issue Mar 13, 2015 · 2 comments
Open

Add flag alias feature to rename old flag smoothly #65

GoogleCodeExporter opened this issue Mar 13, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

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 [email protected] on 20 Mar 2014 at 3:22

  • Added labels: Milestone-v2.2

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

No branches or pull requests

1 participant