diff --git a/fastn-core/src/library2022/mod.rs b/fastn-core/src/library2022/mod.rs index fdcc74a302..4107921f2f 100644 --- a/fastn-core/src/library2022/mod.rs +++ b/fastn-core/src/library2022/mod.rs @@ -223,7 +223,7 @@ impl Library2022 { processor::figma_tokens::process_figma_tokens_old(value, kind, doc) } "http" => processor::http::process(value, kind, doc, self).await, - "tutor" => fastn_core::tutor::process(value, kind, doc).await, + "tutor-data" => fastn_core::tutor::process(value, kind, doc).await, "toc" => processor::toc::process(value, kind, doc), "get-data" => processor::get_data::process(value, kind, doc, self), "sitemap" => processor::sitemap::process(value, kind, doc, self), diff --git a/fastn-core/src/tutor.rs b/fastn-core/src/tutor.rs index df71ee00c5..60680173a3 100644 --- a/fastn-core/src/tutor.rs +++ b/fastn-core/src/tutor.rs @@ -1,4 +1,4 @@ -pub async fn main(package_name: String) -> fastn_core::Result<()> { +pub async fn main() -> fastn_core::Result<()> { println!("starting TUTOR mode"); std::env::set_current_dir(std::env::current_dir()?.join(".tutor"))?; fastn_core::listen( @@ -10,7 +10,7 @@ pub async fn main(package_name: String) -> fastn_core::Result<()> { vec![], vec![], vec![], - package_name, + "the-tutor".to_string(), ) .await } @@ -27,24 +27,21 @@ pub async fn js() -> fastn_core::Result { Ok(actix_web::HttpResponse::Ok().body(include_bytes!("../tutor.js").to_vec())) } -pub async fn start(t: Tutorial) -> fastn_core::Result { +async fn set_tutorial(t: Option) -> fastn_core::Result { if !is_tutor() { return Ok(fastn_core::not_found!("this only works in tutor mode")); } - println!("/-/start/ called"); - *CURRENT_TUTORIAL.write().await = Some(t); + *CURRENT_TUTORIAL.write().await = t; fastn_core::http::api_ok("done") } -pub async fn stop() -> fastn_core::Result { - if !is_tutor() { - return Ok(fastn_core::not_found!("this only works in tutor mode")); - } +pub async fn start(t: Tutorial) -> fastn_core::Result { + set_tutorial(Some(t)).await +} - println!("/-/stop/ called, shutting down"); - *CURRENT_TUTORIAL.write().await = None; - fastn_core::http::api_ok("done") +pub async fn stop() -> fastn_core::Result { + set_tutorial(None).await } static CURRENT_TUTORIAL: once_cell::sync::Lazy>> = @@ -76,6 +73,7 @@ pub(crate) async fn config( Ok((config, app_data.package_name)) } +/// tutor-data $processor$ pub async fn process( value: ftd::ast::VariableValue, kind: ftd::interpreter::Kind, @@ -87,7 +85,6 @@ pub async fn process( )); } - dbg!("tutor process called"); let state = match tokio::fs::read(dirs::home_dir().unwrap().join(".fastn").join("tutor.json")).await { Ok(v) => serde_json::from_slice(&v)?, @@ -102,7 +99,6 @@ pub async fn process( } }, }; - dbg!(&state); doc.from_json(&state, &kind, &value) } @@ -116,5 +112,5 @@ struct TutorState { pub fn is_tutor() -> bool { // https://github.com/orgs/fastn-stack/discussions/1414 // with either of these are passed we allow APIs like /-/shutdown/, `/-/start/` etc - std::env::args().any(|e| e == "tutor" || e == "--tutor") + std::env::args().any(|e| e == "tutor") } diff --git a/fastn/src/main.rs b/fastn/src/main.rs index 66ff856550..a4f982fedf 100644 --- a/fastn/src/main.rs +++ b/fastn/src/main.rs @@ -81,7 +81,7 @@ async fn fastn_core_commands(matches: &clap::ArgMatches) -> fastn_core::Result<( } if let Some(_tutor) = matches.subcommand_matches("tutor") { - return fastn_core::tutor::main("the-tutor".to_string()).await; + return fastn_core::tutor::main().await; } let mut config = fastn_core::Config::read(None, true).await?; @@ -506,7 +506,6 @@ mod sub_command { .action(clap::ArgAction::Append)) .arg(clap::arg!(--"css" "CSS text added in ftd files") .action(clap::ArgAction::Append)) - .arg(clap::arg!(--"tutor" "Start the server in tutor mode").hide(true)) .arg(clap::arg!(--"download-base-url" "If running without files locally, download needed files from here")); if cfg!(feature = "remote") { serve