From e3906b3269ad2baff31db98839607539d9b7f26f Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 23 Jun 2022 12:00:19 -0400 Subject: [PATCH] Split help out of main.rs --- zerotier-system-service/src/cmdline_help.rs | 83 ++++++++++++++++++++ zerotier-system-service/src/main.rs | 86 +-------------------- 2 files changed, 86 insertions(+), 83 deletions(-) create mode 100644 zerotier-system-service/src/cmdline_help.rs diff --git a/zerotier-system-service/src/cmdline_help.rs b/zerotier-system-service/src/cmdline_help.rs new file mode 100644 index 000000000..0ad7d022a --- /dev/null +++ b/zerotier-system-service/src/cmdline_help.rs @@ -0,0 +1,83 @@ +// (c) 2020-2022 ZeroTier, Inc. -- currently propritery pending actual release and licensing. See LICENSE.md. + +use zerotier_network_hypervisor::{VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION}; + +pub fn make_cmdline_help() -> String { + format!( + r###"ZeroTier Network Hypervisor Service Version {}.{}.{} +(c)2013-2022 ZeroTier, Inc. +Licensed under the Mozilla Public License (MPL) 2.0 + +Usage: zerotier [-...] [command args] + +Global Options: + + -j Output raw JSON where applicable + -p Use alternate base path + -t Load secret auth token from a file + -T Set secret token on command line + +Common Operations: + + help Show this help + version Print version (of this binary) + +· status Show node status and configuration + +· set [setting] [value] List all settings (with no args) +· port Primary P2P port +· secondaryport Secondary P2P port (0 to disable) +· blacklist cidr Toggle physical path blacklisting +· blacklist if [Un]blacklist interface prefix +· portmap Toggle use of uPnP and NAT-PMP + +· peer [option] +· show
Show detailed peer information +· list List peers +· listroots List root peers +· try
[...] Try peer at explicit endpoint + +· network [option] +· show Show detailed network information +· list List networks +· set [option] [value] Get or set network options +· manageips Is IP management allowed? +· manageroutes Is route management allowed? +· managedns Allow network to push DNS config +· globalips Allow assignment of global IPs? +· globalroutes Can global IP routes be set? +· defaultroute Can default route be overridden? + +· join Join a virtual network +· leave Leave a virtual network + +Advanced Operations: + + identity [args] + new Create new identity + getpublic Extract public part of identity + fingerprint Get an identity's fingerprint + validate Locally validate an identity + sign <@file> Sign a file with an identity's key + verify <@file> Verify a signature + + rootset [args] +· add <@root set> Add or update a root set +· remove Stop using a root set +· list List root sets in use + sign Sign a root set with an identity + verify Load and verify a root set + marshal Dump root set as binary to stdout + restoredefault (Re-)add built-in default root set + + service Start local service + (usually not invoked manually) + + · Command requires a running node to control. + @ Argument is the path to a file containing the object. + ? Argument can be either the object or a path to it (auto-detected). + +"###, + VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, + ) +} diff --git a/zerotier-system-service/src/main.rs b/zerotier-system-service/src/main.rs index ed5bb9610..ddde7af4e 100644 --- a/zerotier-system-service/src/main.rs +++ b/zerotier-system-service/src/main.rs @@ -1,6 +1,7 @@ // (c) 2020-2022 ZeroTier, Inc. -- currently propritery pending actual release and licensing. See LICENSE.md. pub mod cli; +pub mod cmdline_help; pub mod datadir; pub mod exitcode; pub mod getifaddrs; @@ -21,88 +22,8 @@ use clap::{Arg, ArgMatches, Command}; use zerotier_network_hypervisor::{VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION}; -fn make_help() -> String { - format!( - r###"ZeroTier Network Hypervisor Service Version {}.{}.{} -(c)2013-2022 ZeroTier, Inc. -Licensed under the Mozilla Public License (MPL) 2.0 - -Usage: zerotier [-...] [command args] - -Global Options: - - -j Output raw JSON where applicable - -p Use alternate base path - -t Load secret auth token from a file - -T Set secret token on command line - -Common Operations: - - help Show this help - version Print version (of this binary) - -· status Show node status and configuration - -· set [setting] [value] List all settings (with no args) -· port Primary P2P port -· secondaryport Secondary P2P port (0 to disable) -· blacklist cidr Toggle physical path blacklisting -· blacklist if [Un]blacklist interface prefix -· portmap Toggle use of uPnP and NAT-PMP - -· peer [option] -· show
Show detailed peer information -· list List peers -· listroots List root peers -· try
[...] Try peer at explicit endpoint - -· network [option] -· show Show detailed network information -· list List networks -· set [option] [value] Get or set network options -· manageips Is IP management allowed? -· manageroutes Is route management allowed? -· managedns Allow network to push DNS config -· globalips Allow assignment of global IPs? -· globalroutes Can global IP routes be set? -· defaultroute Can default route be overridden? - -· join Join a virtual network -· leave Leave a virtual network - -Advanced Operations: - - identity [args] - new Create new identity - getpublic Extract public part of identity - fingerprint Get an identity's fingerprint - validate Locally validate an identity - sign <@file> Sign a file with an identity's key - verify <@file> Verify a signature - - rootset [args] -· add <@root set> Add or update a root set -· remove Stop using a root set -· list List root sets in use - sign Sign a root set with an identity - verify Load and verify a root set - marshal Dump root set as binary to stdout - restoredefault (Re-)add built-in default root set - - service Start local service - (usually not invoked manually) - - · Command requires a running node to control. - @ Argument is the path to a file containing the object. - ? Argument can be either the object or a path to it (auto-detected). - -"###, - VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, - ) -} - pub fn print_help() { - let h = make_help(); + let h = crate::cmdline_help::make_cmdline_help(); let _ = std::io::stdout().write_all(h.as_bytes()); } @@ -163,7 +84,6 @@ async fn async_main(flags: Flags, global_args: Box) -> i32 { fn main() { let global_args = Box::new({ - let help = make_help(); Command::new("zerotier") .arg(Arg::new("json").short('j')) .arg(Arg::new("path").short('p').takes_value(true)) @@ -213,7 +133,7 @@ fn main() { .subcommand(Command::new("marshal").arg(Arg::new("path").index(1).required(true))) .subcommand(Command::new("restoredefault")), ) - .override_help(help.as_str()) + .override_help(crate::cmdline_help::make_cmdline_help().as_str()) .override_usage("") .disable_version_flag(true) .disable_help_subcommand(false)