mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 06:19:44 +00:00
add with_about for CLI commands (#2741)
* add with_about for echo, server, and auth * update for feedback * finish (most) remaining command documentation * update comments after additional clarification * add expanded_api descriptions * add comments for action_api * add comments for remaining apis * add comment for package-rebuild * fix build errors * missed one with_about * add context to git-info subcommands * remove context from git-info subcommands * Make git-info from_fns generic over context * make version::git_info generic over the context * try removing generics from subcommand and version::git_info * try adding a closure with context * Updates for reviewer feedback
This commit is contained in:
@@ -114,29 +114,71 @@ impl std::fmt::Display for ApiState {
|
||||
|
||||
pub fn main_api<C: Context>() -> ParentHandler<C> {
|
||||
let api = ParentHandler::new()
|
||||
.subcommand::<C, _>("git-info", from_fn(version::git_info))
|
||||
.subcommand(
|
||||
"git-info",
|
||||
from_fn(|_: RpcContext| version::git_info())
|
||||
.with_about("Display the githash of StartOS CLI"),
|
||||
)
|
||||
.subcommand(
|
||||
"echo",
|
||||
from_fn(echo::<RpcContext>)
|
||||
.with_metadata("authenticated", Value::Bool(false))
|
||||
.with_about("Echo a message")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"state",
|
||||
from_fn(|_: RpcContext| Ok::<_, Error>(ApiState::Running))
|
||||
.with_metadata("authenticated", Value::Bool(false))
|
||||
.with_about("Display the API that is currently serving")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand("server", server::<C>())
|
||||
.subcommand("package", package::<C>())
|
||||
.subcommand("net", net::net::<C>())
|
||||
.subcommand("auth", auth::auth::<C>())
|
||||
.subcommand("db", db::db::<C>())
|
||||
.subcommand("ssh", ssh::ssh::<C>())
|
||||
.subcommand("wifi", net::wifi::wifi::<C>())
|
||||
.subcommand("disk", disk::disk::<C>())
|
||||
.subcommand("notification", notifications::notification::<C>())
|
||||
.subcommand("backup", backup::backup::<C>())
|
||||
.subcommand(
|
||||
"server",
|
||||
server::<C>()
|
||||
.with_about("Commands related to the server i.e. restart, update, and shutdown"),
|
||||
)
|
||||
.subcommand(
|
||||
"package",
|
||||
package::<C>().with_about("Commands related to packages"),
|
||||
)
|
||||
.subcommand(
|
||||
"net",
|
||||
net::net::<C>().with_about("Network commands related to tor and dhcp"),
|
||||
)
|
||||
.subcommand(
|
||||
"auth",
|
||||
auth::auth::<C>().with_about(
|
||||
"Commands related to Authentication i.e. login, logout, reset-password",
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
"db",
|
||||
db::db::<C>().with_about("Commands to interact with the db i.e. dump, put, apply"),
|
||||
)
|
||||
.subcommand(
|
||||
"ssh",
|
||||
ssh::ssh::<C>()
|
||||
.with_about("Commands for interacting with ssh keys i.e. add, delete, list"),
|
||||
)
|
||||
.subcommand(
|
||||
"wifi",
|
||||
net::wifi::wifi::<C>()
|
||||
.with_about("Commands related to wifi networks i.e. add, connect, delete"),
|
||||
)
|
||||
.subcommand(
|
||||
"disk",
|
||||
disk::disk::<C>().with_about("Commands for listing disk info and repairing"),
|
||||
)
|
||||
.subcommand(
|
||||
"notification",
|
||||
notifications::notification::<C>().with_about("Create, delete, or list notifications"),
|
||||
)
|
||||
.subcommand(
|
||||
"backup",
|
||||
backup::backup::<C>()
|
||||
.with_about("Commands related to backup creation and backup targets"),
|
||||
)
|
||||
.subcommand(
|
||||
"registry",
|
||||
CallRemoteHandler::<RpcContext, _, _, RegistryUrlParams>::new(
|
||||
@@ -144,10 +186,20 @@ pub fn main_api<C: Context>() -> ParentHandler<C> {
|
||||
)
|
||||
.no_cli(),
|
||||
)
|
||||
.subcommand("s9pk", s9pk::rpc::s9pk())
|
||||
.subcommand("util", util::rpc::util::<C>());
|
||||
.subcommand(
|
||||
"s9pk",
|
||||
s9pk::rpc::s9pk().with_about("Commands for interacting with s9pk files"),
|
||||
)
|
||||
.subcommand(
|
||||
"util",
|
||||
util::rpc::util::<C>().with_about("Command for calculating the blake3 hash of a file"),
|
||||
);
|
||||
#[cfg(feature = "dev")]
|
||||
let api = api.subcommand("lxc", lxc::dev::lxc::<C>());
|
||||
let api = api.subcommand(
|
||||
"lxc",
|
||||
lxc::dev::lxc::<C>()
|
||||
.with_about("Commands related to lxc containers i.e. create, list, remove, connect"),
|
||||
);
|
||||
api
|
||||
}
|
||||
|
||||
@@ -160,42 +212,57 @@ pub fn server<C: Context>() -> ParentHandler<C> {
|
||||
.with_custom_display_fn(|handle, result| {
|
||||
Ok(system::display_time(handle.params, result))
|
||||
})
|
||||
.with_call_remote::<CliContext>(),
|
||||
.with_about("Display current time and server uptime")
|
||||
.with_call_remote::<CliContext>()
|
||||
)
|
||||
.subcommand(
|
||||
"experimental",
|
||||
system::experimental::<C>()
|
||||
.with_about("Commands related to configuring experimental options such as zram and cpu governor"),
|
||||
)
|
||||
.subcommand("experimental", system::experimental::<C>())
|
||||
.subcommand("logs", system::logs::<RpcContext>())
|
||||
.subcommand(
|
||||
"logs",
|
||||
from_fn_async(logs::cli_logs::<RpcContext, Empty>).no_display(),
|
||||
system::logs::<RpcContext>().with_about("Display OS logs"),
|
||||
)
|
||||
.subcommand(
|
||||
"logs",
|
||||
from_fn_async(logs::cli_logs::<RpcContext, Empty>).no_display().with_about("Display OS logs"),
|
||||
)
|
||||
.subcommand("kernel-logs", system::kernel_logs::<RpcContext>())
|
||||
.subcommand(
|
||||
"kernel-logs",
|
||||
from_fn_async(logs::cli_logs::<RpcContext, Empty>).no_display(),
|
||||
system::kernel_logs::<RpcContext>().with_about("Display Kernel logs"),
|
||||
)
|
||||
.subcommand(
|
||||
"kernel-logs",
|
||||
from_fn_async(logs::cli_logs::<RpcContext, Empty>).no_display().with_about("Display Kernel logs"),
|
||||
)
|
||||
.subcommand(
|
||||
"metrics",
|
||||
from_fn_async(system::metrics)
|
||||
.with_display_serializable()
|
||||
.with_call_remote::<CliContext>(),
|
||||
.with_about("Display information about the server i.e. temperature, RAM, CPU, and disk usage")
|
||||
.with_call_remote::<CliContext>()
|
||||
)
|
||||
.subcommand(
|
||||
"shutdown",
|
||||
from_fn_async(shutdown::shutdown)
|
||||
.no_display()
|
||||
.with_call_remote::<CliContext>(),
|
||||
.with_about("Shutdown the server")
|
||||
.with_call_remote::<CliContext>()
|
||||
)
|
||||
.subcommand(
|
||||
"restart",
|
||||
from_fn_async(shutdown::restart)
|
||||
.no_display()
|
||||
.with_call_remote::<CliContext>(),
|
||||
.with_about("Restart the server")
|
||||
.with_call_remote::<CliContext>()
|
||||
)
|
||||
.subcommand(
|
||||
"rebuild",
|
||||
from_fn_async(shutdown::rebuild)
|
||||
.no_display()
|
||||
.with_call_remote::<CliContext>(),
|
||||
.with_about("Teardown and rebuild service containers")
|
||||
.with_call_remote::<CliContext>()
|
||||
)
|
||||
.subcommand(
|
||||
"update",
|
||||
@@ -205,7 +272,7 @@ pub fn server<C: Context>() -> ParentHandler<C> {
|
||||
)
|
||||
.subcommand(
|
||||
"update",
|
||||
from_fn_async(update::cli_update_system).no_display(),
|
||||
from_fn_async(update::cli_update_system).no_display().with_about("Check a given registry for StartOS updates and update if available"),
|
||||
)
|
||||
.subcommand(
|
||||
"update-firmware",
|
||||
@@ -220,25 +287,31 @@ pub fn server<C: Context>() -> ParentHandler<C> {
|
||||
.with_custom_display_fn(|_handle, result| {
|
||||
Ok(firmware::display_firmware_update_result(result))
|
||||
})
|
||||
.with_call_remote::<CliContext>(),
|
||||
.with_about("Update the mainboard's firmware to the latest firmware available in this version of StartOS if available. Note: This command does not reach out to the Internet")
|
||||
.with_call_remote::<CliContext>()
|
||||
)
|
||||
.subcommand(
|
||||
"set-smtp",
|
||||
from_fn_async(system::set_system_smtp)
|
||||
.no_display()
|
||||
.with_call_remote::<CliContext>(),
|
||||
.with_about("Set system smtp server and credentials")
|
||||
.with_call_remote::<CliContext>()
|
||||
)
|
||||
.subcommand(
|
||||
"clear-smtp",
|
||||
from_fn_async(system::clear_system_smtp)
|
||||
.no_display()
|
||||
.with_call_remote::<CliContext>(),
|
||||
.with_about("Remove system smtp server and credentials")
|
||||
.with_call_remote::<CliContext>()
|
||||
)
|
||||
}
|
||||
|
||||
pub fn package<C: Context>() -> ParentHandler<C> {
|
||||
ParentHandler::new()
|
||||
.subcommand("action", action::action_api::<C>())
|
||||
.subcommand(
|
||||
"action",
|
||||
action::action_api::<C>().with_about("Commands to get action input or run an action"),
|
||||
)
|
||||
.subcommand(
|
||||
"install",
|
||||
from_fn_async(install::install)
|
||||
@@ -251,24 +324,32 @@ pub fn package<C: Context>() -> ParentHandler<C> {
|
||||
.with_metadata("get_session", Value::Bool(true))
|
||||
.no_cli(),
|
||||
)
|
||||
.subcommand("install", from_fn_async(install::cli_install).no_display())
|
||||
.subcommand(
|
||||
"install",
|
||||
from_fn_async(install::cli_install)
|
||||
.no_display()
|
||||
.with_about("Install a package from a marketplace or via sideloading"),
|
||||
)
|
||||
.subcommand(
|
||||
"uninstall",
|
||||
from_fn_async(install::uninstall)
|
||||
.with_metadata("sync_db", Value::Bool(true))
|
||||
.no_display()
|
||||
.with_about("Remove a package")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"list",
|
||||
from_fn_async(install::list)
|
||||
.with_display_serializable()
|
||||
.with_about("List installed packages")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"installed-version",
|
||||
from_fn_async(install::installed_version)
|
||||
.with_display_serializable()
|
||||
.with_about("Display installed version for a PackageId")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
@@ -276,6 +357,7 @@ pub fn package<C: Context>() -> ParentHandler<C> {
|
||||
from_fn_async(control::start)
|
||||
.with_metadata("sync_db", Value::Bool(true))
|
||||
.no_display()
|
||||
.with_about("Start a package container")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
@@ -283,6 +365,7 @@ pub fn package<C: Context>() -> ParentHandler<C> {
|
||||
from_fn_async(control::stop)
|
||||
.with_metadata("sync_db", Value::Bool(true))
|
||||
.no_display()
|
||||
.with_about("Stop a package container")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
@@ -290,6 +373,7 @@ pub fn package<C: Context>() -> ParentHandler<C> {
|
||||
from_fn_async(control::restart)
|
||||
.with_metadata("sync_db", Value::Bool(true))
|
||||
.no_display()
|
||||
.with_about("Restart a package container")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
@@ -297,12 +381,19 @@ pub fn package<C: Context>() -> ParentHandler<C> {
|
||||
from_fn_async(service::rebuild)
|
||||
.with_metadata("sync_db", Value::Bool(true))
|
||||
.no_display()
|
||||
.with_about("Rebuild service container")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand("logs", logs::package_logs())
|
||||
.subcommand(
|
||||
"logs",
|
||||
from_fn_async(logs::cli_logs::<RpcContext, logs::PackageIdParams>).no_display(),
|
||||
logs::package_logs().with_about("Display package logs"),
|
||||
)
|
||||
.subcommand(
|
||||
"logs",
|
||||
from_fn_async(logs::cli_logs::<RpcContext, logs::PackageIdParams>)
|
||||
.no_display()
|
||||
.with_about("Display package logs"),
|
||||
)
|
||||
.subcommand(
|
||||
"properties",
|
||||
@@ -310,13 +401,20 @@ pub fn package<C: Context>() -> ParentHandler<C> {
|
||||
.with_custom_display_fn(|_handle, result| {
|
||||
Ok(properties::display_properties(result))
|
||||
})
|
||||
.with_about("Display package Properties")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand("backup", backup::package_backup::<C>())
|
||||
.subcommand(
|
||||
"backup",
|
||||
backup::package_backup::<C>()
|
||||
.with_about("Commands for restoring package(s) from backup"),
|
||||
)
|
||||
.subcommand("connect", from_fn_async(service::connect_rpc).no_cli())
|
||||
.subcommand(
|
||||
"connect",
|
||||
from_fn_async(service::connect_rpc_cli).no_display(),
|
||||
from_fn_async(service::connect_rpc_cli)
|
||||
.no_display()
|
||||
.with_about("Connect to a LXC container"),
|
||||
)
|
||||
.subcommand(
|
||||
"attach",
|
||||
@@ -329,74 +427,124 @@ pub fn package<C: Context>() -> ParentHandler<C> {
|
||||
|
||||
pub fn diagnostic_api() -> ParentHandler<DiagnosticContext> {
|
||||
ParentHandler::new()
|
||||
.subcommand::<DiagnosticContext, _>(
|
||||
.subcommand(
|
||||
"git-info",
|
||||
from_fn(version::git_info).with_metadata("authenticated", Value::Bool(false)),
|
||||
from_fn(|_: DiagnosticContext| version::git_info())
|
||||
.with_metadata("authenticated", Value::Bool(false))
|
||||
.with_about("Display the githash of StartOS CLI"),
|
||||
)
|
||||
.subcommand(
|
||||
"echo",
|
||||
from_fn(echo::<DiagnosticContext>).with_call_remote::<CliContext>(),
|
||||
from_fn(echo::<DiagnosticContext>)
|
||||
.with_about("Echo a message")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"state",
|
||||
from_fn(|_: DiagnosticContext| Ok::<_, Error>(ApiState::Error))
|
||||
.with_metadata("authenticated", Value::Bool(false))
|
||||
.with_about("Display the API that is currently serving")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand("diagnostic", diagnostic::diagnostic::<DiagnosticContext>())
|
||||
.subcommand(
|
||||
"diagnostic",
|
||||
diagnostic::diagnostic::<DiagnosticContext>()
|
||||
.with_about("Diagnostic commands i.e. logs, restart, rebuild"),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn init_api() -> ParentHandler<InitContext> {
|
||||
ParentHandler::new()
|
||||
.subcommand::<InitContext, _>(
|
||||
.subcommand(
|
||||
"git-info",
|
||||
from_fn(version::git_info).with_metadata("authenticated", Value::Bool(false)),
|
||||
from_fn(|_: InitContext| version::git_info())
|
||||
.with_metadata("authenticated", Value::Bool(false))
|
||||
.with_about("Display the githash of StartOS CLI"),
|
||||
)
|
||||
.subcommand(
|
||||
"echo",
|
||||
from_fn(echo::<InitContext>).with_call_remote::<CliContext>(),
|
||||
from_fn(echo::<InitContext>)
|
||||
.with_about("Echo a message")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"state",
|
||||
from_fn(|_: InitContext| Ok::<_, Error>(ApiState::Initializing))
|
||||
.with_metadata("authenticated", Value::Bool(false))
|
||||
.with_about("Display the API that is currently serving")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand("init", init::init_api::<InitContext>())
|
||||
.subcommand(
|
||||
"init",
|
||||
init::init_api::<InitContext>()
|
||||
.with_about("Commands to get logs or initialization progress"),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn setup_api() -> ParentHandler<SetupContext> {
|
||||
ParentHandler::new()
|
||||
.subcommand::<SetupContext, _>(
|
||||
.subcommand(
|
||||
"git-info",
|
||||
from_fn(version::git_info).with_metadata("authenticated", Value::Bool(false)),
|
||||
from_fn(|_: SetupContext| version::git_info())
|
||||
.with_metadata("authenticated", Value::Bool(false))
|
||||
.with_about("Display the githash of StartOS CLI"),
|
||||
)
|
||||
.subcommand(
|
||||
"echo",
|
||||
from_fn(echo::<SetupContext>).with_call_remote::<CliContext>(),
|
||||
from_fn(echo::<SetupContext>)
|
||||
.with_about("Echo a message")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand("setup", setup::setup::<SetupContext>())
|
||||
}
|
||||
|
||||
pub fn install_api() -> ParentHandler<InstallContext> {
|
||||
ParentHandler::new()
|
||||
.subcommand::<InstallContext, _>(
|
||||
.subcommand(
|
||||
"git-info",
|
||||
from_fn(version::git_info).with_metadata("authenticated", Value::Bool(false)),
|
||||
from_fn(|_: InstallContext| version::git_info())
|
||||
.with_metadata("authenticated", Value::Bool(false))
|
||||
.with_about("Display the githash of StartOS CLI"),
|
||||
)
|
||||
.subcommand(
|
||||
"echo",
|
||||
from_fn(echo::<InstallContext>).with_call_remote::<CliContext>(),
|
||||
from_fn(echo::<InstallContext>)
|
||||
.with_about("Echo a message")
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"install",
|
||||
os_install::install::<InstallContext>()
|
||||
.with_about("Commands to list disk info, install StartOS, and reboot"),
|
||||
)
|
||||
.subcommand("install", os_install::install::<InstallContext>())
|
||||
}
|
||||
|
||||
pub fn expanded_api() -> ParentHandler<CliContext> {
|
||||
main_api()
|
||||
.subcommand("init", from_fn_blocking(developer::init).no_display())
|
||||
.subcommand("pubkey", from_fn_blocking(developer::pubkey))
|
||||
.subcommand("diagnostic", diagnostic::diagnostic::<CliContext>())
|
||||
.subcommand(
|
||||
"init",
|
||||
from_fn_blocking(developer::init)
|
||||
.no_display()
|
||||
.with_about("Create developer key if it doesn't exist"),
|
||||
)
|
||||
.subcommand(
|
||||
"pubkey",
|
||||
from_fn_blocking(developer::pubkey)
|
||||
.with_about("Get public key for developer private key"),
|
||||
)
|
||||
.subcommand(
|
||||
"diagnostic",
|
||||
diagnostic::diagnostic::<CliContext>()
|
||||
.with_about("Commands to display logs, restart the server, etc"),
|
||||
)
|
||||
.subcommand("setup", setup::setup::<CliContext>())
|
||||
.subcommand("install", os_install::install::<CliContext>())
|
||||
.subcommand("registry", registry::registry_api::<CliContext>())
|
||||
.subcommand(
|
||||
"install",
|
||||
os_install::install::<CliContext>()
|
||||
.with_about("Commands to list disk info, install StartOS, and reboot"),
|
||||
)
|
||||
.subcommand(
|
||||
"registry",
|
||||
registry::registry_api::<CliContext>().with_about("Commands related to the registry"),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user