Federated blogging application, thanks to ActivityPub https://joinplu.me
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
1.9 KiB

  1. use dotenv;
  2. use clap::App;
  3. use plume_models::{db_conn::init_pool, instance::Instance};
  4. use std::io::{self, prelude::*};
  5. mod instance;
  6. mod migration;
  7. mod search;
  8. mod users;
  9. fn main() {
  10. let mut app = App::new("Plume CLI")
  11. .bin_name("plm")
  12. .version(env!("CARGO_PKG_VERSION"))
  13. .about("Collection of tools to manage your Plume instance.")
  14. .subcommand(instance::command())
  15. .subcommand(migration::command())
  16. .subcommand(search::command())
  17. .subcommand(users::command());
  18. let matches = app.clone().get_matches();
  19. match dotenv::dotenv() {
  20. Ok(path) => println!("Configuration read from {}", path.display()),
  21. Err(ref e) if e.not_found() => eprintln!("no .env was found"),
  22. e => e.map(|_| ()).unwrap(),
  23. }
  24. let db_pool = init_pool()
  25. .expect("Couldn't create a database pool, please check DATABASE_URL in your .env");
  26. let _ = db_pool
  27. .get()
  28. .as_ref()
  29. .map(|conn| Instance::cache_local(conn));
  30. match matches.subcommand() {
  31. ("instance", Some(args)) => instance::run(
  32. args,
  33. &db_pool.get().expect("Couldn't connect to the database."),
  34. ),
  35. ("migration", Some(args)) => migration::run(
  36. args,
  37. &db_pool.get().expect("Couldn't connect to the database."),
  38. ),
  39. ("search", Some(args)) => search::run(args, db_pool),
  40. ("users", Some(args)) => users::run(
  41. args,
  42. &db_pool.get().expect("Couldn't connect to the database."),
  43. ),
  44. _ => app.print_help().expect("Couldn't print help"),
  45. };
  46. }
  47. pub fn ask_for(something: &str) -> String {
  48. print!("{}: ", something);
  49. io::stdout().flush().expect("Couldn't flush STDOUT");
  50. let mut input = String::new();
  51. io::stdin()
  52. .read_line(&mut input)
  53. .expect("Unable to read line");
  54. input.retain(|c| c != '\n');
  55. input
  56. }