Skip to content

Best practice to access arguments throughout an application #5258

Closed Answered by epage
mnlm asked this question in Q&A
Discussion options

You must be logged in to vote

The patterns I've seen used that seem to make the most sense

  • Pass the individual fields around as needed
  • Have an application wide Context that you put the fields into and pass that around
  • When using subcommands, have run functions on the individual subcommands which directly read their structs

These can be mixed together. For example, cargo-release uses the subcommand run functions (https://github.com/crate-ci/cargo-release/blob/master/src/bin/cargo-release.rs) which will access individual fields (https://github.com/crate-ci/cargo-release/blob/master/src/steps/owner.rs#L42) but also layers parts of the struct into the config (https://github.com/crate-ci/cargo-release/blob/master/src/ste…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by mnlm
Comment options

You must be logged in to vote
1 reply
@epage
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants