cli.rs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. use clap::{AppSettings, ArgGroup, Parser};
  2. use lazy_static::lazy_static;
  3. #[derive(clap::ArgEnum, Clone, Debug, Copy)]
  4. pub enum KeypairType {
  5. X25519,
  6. X448,
  7. }
  8. lazy_static! {
  9. static ref VERSION: &'static str = {
  10. match option_env!("VERGEN_GIT_SEMVER_LIGHTWEIGHT") {
  11. Some(v) => v,
  12. None => env!("VERGEN_BUILD_SEMVER"),
  13. }
  14. };
  15. static ref LONG_VERSION: String = format!(
  16. "
  17. Build Timestamp: {}
  18. Build Version: {}
  19. Commit SHA: {:?}
  20. Commit Date: {:?}
  21. Commit Branch: {:?}
  22. cargo Target Triple: {}
  23. cargo Profile: {}
  24. cargo Features: {}
  25. ",
  26. env!("VERGEN_BUILD_TIMESTAMP"),
  27. env!("VERGEN_BUILD_SEMVER"),
  28. option_env!("VERGEN_GIT_SHA"),
  29. option_env!("VERGEN_GIT_COMMIT_TIMESTAMP"),
  30. option_env!("VERGEN_GIT_BRANCH"),
  31. env!("VERGEN_CARGO_TARGET_TRIPLE"),
  32. env!("VERGEN_CARGO_PROFILE"),
  33. env!("VERGEN_CARGO_FEATURES")
  34. );
  35. }
  36. #[derive(Parser, Debug, Default, Clone)]
  37. #[clap(
  38. about,
  39. version(*VERSION),
  40. long_version(LONG_VERSION.as_str()),
  41. setting(AppSettings::DeriveDisplayOrder)
  42. )]
  43. #[clap(group(
  44. ArgGroup::new("cmds")
  45. .required(true)
  46. .args(&["CONFIG", "genkey"]),
  47. ))]
  48. pub struct Cli {
  49. /// The path to the configuration file
  50. ///
  51. /// Running as a client or a server is automatically determined
  52. /// according to the configuration file.
  53. #[clap(parse(from_os_str), name = "CONFIG")]
  54. pub config_path: Option<std::path::PathBuf>,
  55. /// Run as a server
  56. #[clap(long, short, group = "mode")]
  57. pub server: bool,
  58. /// Run as a client
  59. #[clap(long, short, group = "mode")]
  60. pub client: bool,
  61. /// Generate a keypair for the use of the noise protocol
  62. ///
  63. /// The DH function to use is x25519
  64. #[clap(long, arg_enum, value_name = "CURVE")]
  65. pub genkey: Option<Option<KeypairType>>,
  66. }