mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
Feature/new registry (#2612)
* wip * overhaul boot process * wip: new registry * wip * wip * wip * wip * wip * wip * os registry complete * ui fixes * fixes * fixes * more fixes * fix merkle archive
This commit is contained in:
@@ -1,38 +1,48 @@
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use clap::Parser;
|
||||
use rpc_toolkit::yajrc::RpcError;
|
||||
use rpc_toolkit::{command, from_fn, from_fn_async, AnyContext, HandlerExt, ParentHandler};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ts_rs::TS;
|
||||
use rpc_toolkit::{
|
||||
from_fn, from_fn_async, CallRemoteHandler, Context, Empty, HandlerExt, ParentHandler,
|
||||
};
|
||||
|
||||
use crate::context::{CliContext, DiagnosticContext};
|
||||
use crate::context::{CliContext, DiagnosticContext, RpcContext};
|
||||
use crate::init::SYSTEM_REBUILD_PATH;
|
||||
use crate::logs::{fetch_logs, LogResponse, LogSource};
|
||||
use crate::shutdown::Shutdown;
|
||||
use crate::Error;
|
||||
|
||||
pub fn diagnostic() -> ParentHandler {
|
||||
pub fn diagnostic<C: Context>() -> ParentHandler<C> {
|
||||
ParentHandler::new()
|
||||
.subcommand("error", from_fn(error).with_remote_cli::<CliContext>())
|
||||
.subcommand("logs", from_fn_async(logs).no_cli())
|
||||
.subcommand("error", from_fn(error).with_call_remote::<CliContext>())
|
||||
.subcommand("logs", crate::system::logs::<DiagnosticContext>())
|
||||
.subcommand(
|
||||
"logs",
|
||||
from_fn_async(crate::logs::cli_logs::<DiagnosticContext, Empty>).no_display(),
|
||||
)
|
||||
.subcommand(
|
||||
"kernel-logs",
|
||||
crate::system::kernel_logs::<DiagnosticContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"kernel-logs",
|
||||
from_fn_async(crate::logs::cli_logs::<DiagnosticContext, Empty>).no_display(),
|
||||
)
|
||||
.subcommand(
|
||||
"exit",
|
||||
from_fn(exit).no_display().with_remote_cli::<CliContext>(),
|
||||
from_fn(exit).no_display().with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"restart",
|
||||
from_fn(restart)
|
||||
.no_display()
|
||||
.with_remote_cli::<CliContext>(),
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
.subcommand("disk", disk())
|
||||
.subcommand("disk", disk::<C>())
|
||||
.subcommand(
|
||||
"rebuild",
|
||||
from_fn_async(rebuild)
|
||||
.no_display()
|
||||
.with_remote_cli::<CliContext>(),
|
||||
.with_call_remote::<CliContext>(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -41,26 +51,6 @@ pub fn error(ctx: DiagnosticContext) -> Result<Arc<RpcError>, Error> {
|
||||
Ok(ctx.error.clone())
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Parser, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[command(rename_all = "kebab-case")]
|
||||
pub struct LogsParams {
|
||||
#[ts(type = "number | null")]
|
||||
limit: Option<usize>,
|
||||
cursor: Option<String>,
|
||||
before: bool,
|
||||
}
|
||||
pub async fn logs(
|
||||
_: AnyContext,
|
||||
LogsParams {
|
||||
limit,
|
||||
cursor,
|
||||
before,
|
||||
}: LogsParams,
|
||||
) -> Result<LogResponse, Error> {
|
||||
Ok(fetch_logs(LogSource::System, limit, cursor, before).await?)
|
||||
}
|
||||
|
||||
pub fn exit(ctx: DiagnosticContext) -> Result<(), Error> {
|
||||
ctx.shutdown.send(None).expect("receiver dropped");
|
||||
Ok(())
|
||||
@@ -83,17 +73,20 @@ pub async fn rebuild(ctx: DiagnosticContext) -> Result<(), Error> {
|
||||
restart(ctx)
|
||||
}
|
||||
|
||||
pub fn disk() -> ParentHandler {
|
||||
ParentHandler::new().subcommand(
|
||||
"forget",
|
||||
from_fn_async(forget_disk)
|
||||
.no_display()
|
||||
.with_remote_cli::<CliContext>(),
|
||||
)
|
||||
pub fn disk<C: Context>() -> ParentHandler<C> {
|
||||
ParentHandler::new()
|
||||
.subcommand("forget", from_fn_async(forget_disk::<C>).no_cli())
|
||||
.subcommand(
|
||||
"forget",
|
||||
CallRemoteHandler::<CliContext, _, _>::new(
|
||||
from_fn_async(forget_disk::<RpcContext>).no_display(),
|
||||
)
|
||||
.no_display(),
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn forget_disk(_: AnyContext) -> Result<(), Error> {
|
||||
let disk_guid = Path::new("/media/embassy/config/disk.guid");
|
||||
pub async fn forget_disk<C: Context>(_: C) -> Result<(), Error> {
|
||||
let disk_guid = Path::new("/media/startos/config/disk.guid");
|
||||
if tokio::fs::metadata(disk_guid).await.is_ok() {
|
||||
tokio::fs::remove_file(disk_guid).await?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user