-
I'm playing with a port of my old /// Moonfire NVR: security camera network video recorder.
#[derive(Bpaf, Debug)]
#[bpaf(options, version)]
enum Args {
/// Checks database integrity (like fsck).
#[bpaf(command)]
Check(#[bpaf(external(cmds::check::args))] cmds::check::Args),
/// Interactively edits configuration.
#[bpaf(command)]
Config(#[bpaf(external(cmds::config::args))] cmds::config::Args),
// ...several other variants...
} Before with
Now with
If I add The best idea I've got is to have a
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 14 replies
-
This is how I would write it right now
Sort of and I'm planning to revisit help customization within a month or two to take advantage of longer help generated by #159. If it helps - I can add |
Beta Was this translation helpful? Give feedback.
-
Actually, not straightforward with subcommands I think. e.g. |
Beta Was this translation helpful? Give feedback.
-
Released, you should be able to switch to published version. Also I noticed you have this defined in multiple places: /// Directory holding the SQLite3 index database.
///
///
/// default: `/var/lib/moonfire-nvr/db`.
#[bpaf(argument("PATH"), fallback_with(crate::default_db_dir))]
db_dir: std::path::PathBuf, Argument sharing between multiple different parsers was one of the motivations to make the library. You can make a parser for db and then share it across multiple parser: fn parse_db_dir() -> impl Parser<PathBuf> {
argument("PATH").help("Directory holding the SQLite3 index database.\nDefault: `{}`", default_db_dir()).fallback_with(default_db_dir)
} and use it via /// Directory holding the SQLite3 index database. // <- this comment is not used by the parser now
#[bpaf(external(parse_db_dir))]
db_dir: std::path::PathBuf, |
Beta Was this translation helpful? Give feedback.
-
You can use |
Beta Was this translation helpful? Give feedback.
You can use
OptionParser::fallback_to_usage
, see https://github.com/pacak/bpaf/blob/bc42de419b15aba586bd4cd2f0b7874f3f915d38/examples/basic.rs