You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Thanks for bpaf it's the only command-line parser that I tested supporting adjacent commands)
This is already supported by the combinatoric API. However, there is an implicit short or long (as documented) for #[bpaf(env("VAR"))]. That behavior can obviously not be changed, I'm asking for some way to express #[bpaf(env_only("VAR"))].
I essentially have a struct EnvVars, with a bunch of env vars inside the main struct Args.
I would like bpaf derive to:
Not generate any implicit short nor long
Keep them hidden from the help text
My current workaround is to mix combinatoric and derive.
Here's an example. I know it isn't pretty. But it successfully parses everything using bpaf, and all fields within EnvVars are hidden from the help text:
use bpaf::{Bpaf,Parser};fnmain(){let args = args().run();println!("{:#?}", args);}#[derive(Bpaf,Clone,Debug)]#[bpaf(options)]pubstructArgs{#[bpaf(external(env_vars))]vars:EnvVars,}#[derive(Bpaf,Clone,Debug)]structEnvVars{#[bpaf(external(var::<0>))]a:Option<String>,#[bpaf(external(var::<1>))]b:Option<String>,#[bpaf(external(var::<2>))]c:Option<String>,}fnvar<constNAME:usize>() -> impl bpaf::Parser<Option<String>>{constNAMES:[&str;3] = ["A","B","C"];let name = NAMES[NAME];
bpaf::env(name).argument(name).optional()}
While I could manually use std::env::var() or use the envy crate, I would love if I could keep everything streamlined using bpaf.
The text was updated successfully, but these errors were encountered:
At this point I'd implement it something like this, with or without an optional helper inside env_vars
#[derive(Clone, Debug)]
struct EnvVars {
a: Option<String>,
b: Option<String>,
c: Option<String>,
}
fn env_vars() -> impl bpaf::Parser<EnvVars> {
let a = bpaf::env("A").argument("A").optional();
let b = bpaf::env("B").argument("B").optional();
let c = bpaf::env("C").argument("C").optional();
bpaf::construct!(EnvVars { a, b, c })
}
But that's a workaround as well. I need to think a bit about a better approach. Maybe special case long("") into "don't generate a named argument".
(Thanks for
bpaf
it's the only command-line parser that I tested supporting adjacent commands)This is already supported by the combinatoric API. However, there is an implicit short or long (as documented) for
#[bpaf(env("VAR"))]
. That behavior can obviously not be changed, I'm asking for some way to express#[bpaf(env_only("VAR"))]
.I essentially have a
struct EnvVars
, with a bunch of env vars inside the mainstruct Args
.I would like
bpaf
derive to:My current workaround is to mix combinatoric and derive.
Here's an example. I know it isn't pretty. But it successfully parses everything using
bpaf
, and all fields withinEnvVars
are hidden from the help text:While I could manually use
std::env::var()
or use theenvy
crate, I would love if I could keep everything streamlined usingbpaf
.The text was updated successfully, but these errors were encountered: