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

define default from constant #43

Open
jeremyandrews opened this issue Aug 24, 2020 · 2 comments
Open

define default from constant #43

jeremyandrews opened this issue Aug 24, 2020 · 2 comments

Comments

@jeremyandrews
Copy link

I recently switched a project from Structopt to Gumdrop and am generally quite happy with the change. However, one thing I've not been able to figure out how to do is to use a const to define a default value.

Essentially, I define a default port and use this in several places in the code:

/// Constant defining Goose's default port when running a Gaggle.
const DEFAULT_PORT: &str = "5115";

One of the places I was able to use it with structopt was in defining the default value for a couple of run-time configuration options. Is there any way to do this with gumdrop?

For example, if I try this:

    /// Sets port Manager listens on
    #[options(no_short, default = DEFAULT_PORT, meta = "PORT")]
    pub manager_bind_port: u16,

I get the following error:

error: expected literal
    --> src/lib.rs:1945:35
     |
1945 |     #[options(no_short, default = DEFAULT_PORT, meta = "PORT")]
     |                                   ^^^^^^^^^^^^
@flukejones
Copy link

Just a hunch, but what about returning it from an expr default?

@jeremyandrews
Copy link
Author

I've reworked my codebase so I set defaults manually when not otherwise set, instead of relying on gumdrop for this. It was not because of this issue, it was because I also allow for configurable default overrides. Therefore this issue can be closed if it's not something on the gumdrop roadmap, as this is no longer a concern for me.

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