Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

support.rs 826 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  1. use structopt::StructOpt;
  2. use structopt::clap::{App, ArgMatches};
  3. use anyhow::Result;
  4. pub struct CmdEntry<'a> {
  5. app: App<'a,'a>,
  6. runner: fn(&ArgMatches) -> Result<()>
  7. }
  8. impl <'a> CmdEntry<'a> {
  9. pub fn name(&self) -> &str {
  10. self.app.get_name()
  11. }
  12. pub fn app(&self) -> &App<'a,'a> {
  13. &self.app
  14. }
  15. pub fn run(&self, matches: &ArgMatches) -> Result<()> {
  16. (self.runner)(&matches)
  17. }
  18. }
  19. pub trait Command: StructOpt + Sized {
  20. /// Run the command with options
  21. fn exec(self) -> Result<()>;
  22. /// Run the command from arg matches
  23. fn exec_from_clap(matches: &ArgMatches) -> Result<()> {
  24. let opt = Self::from_clap(&matches);
  25. opt.exec()
  26. }
  27. /// Get a command entry
  28. fn get_entry<'a>() -> CmdEntry<'a> {
  29. CmdEntry {
  30. app: Self::clap(),
  31. runner: Self::exec_from_clap
  32. }
  33. }
  34. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...