setup.rs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // imag - the personal information management suite for the commandline
  3. // Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
  4. //
  5. // This library is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU Lesser General Public
  7. // License as published by the Free Software Foundation; version
  8. // 2.1 of the License.
  9. //
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. // Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public
  16. // License along with this library; if not, write to the Free Software
  17. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. //
  19. use clap::App;
  20. use runtime::Runtime;
  21. pub type Name = &'static str;
  22. pub type Version<'a> = &'a str;
  23. pub type About = &'static str;
  24. /// Helper to generate the Runtime object
  25. ///
  26. /// exit()s the program if the runtime couldn't be build, prints error with println!() before
  27. /// exiting
  28. pub fn generate_runtime_setup<'a, B>(name: Name, version: Version<'a>, about: About, builder: B)
  29. -> Runtime<'a>
  30. where B: FnOnce(App<'a, 'a>) -> App<'a, 'a>
  31. {
  32. use std::process::exit;
  33. use libimagerror::trace::trace_error_dbg;
  34. Runtime::new(builder(Runtime::get_default_cli_builder(name, version, about)))
  35. .unwrap_or_else(|e| {
  36. println!("Could not set up Runtime");
  37. println!("{:?}", e);
  38. trace_error_dbg(&e);
  39. exit(1);
  40. })
  41. }