From 5f6ece5f426acebfe712d0ab84db928f6bb737ef Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 12 Mar 2023 17:41:25 +0100 Subject: [PATCH] Add todo and error command --- configs/crystal/create-partitions/up.nu | 3 ++ configs/crystal/install-bootloader/up.nu | 2 +- configs/crystal/install-desktop/up.nu | 1 + configs/crystal/install-flatpak/up.nu | 1 + src/task/commands/error.rs | 51 ++++++++++++++++++++++++ src/task/commands/mod.rs | 4 ++ src/task/commands/todo.rs | 51 ++++++++++++++++++++++++ src/task/exec_builder.rs | 6 ++- src/utils.rs | 2 + 9 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 src/task/commands/error.rs create mode 100644 src/task/commands/todo.rs diff --git a/configs/crystal/create-partitions/up.nu b/configs/crystal/create-partitions/up.nu index 7913296..90c8dcd 100644 --- a/configs/crystal/create-partitions/up.nu +++ b/configs/crystal/create-partitions/up.nu @@ -32,6 +32,7 @@ module auto_partition { } def efi_create_fs_ssd [device: string] { + todo "Implement SSD partitioning" } def efi_create_fs_hdd [device: string] { @@ -56,6 +57,7 @@ module auto_partition { export def bios [device: string] { debug "Creating bios partitions" bios_layout $device + todo "Implement BIOS filesystems" } def bios_layout [device: string] { @@ -80,6 +82,7 @@ def main [cfg] { } } else { info "Creating partitions manually" + todo "Implement manual partitioning" } info "Partitions created!" diff --git a/configs/crystal/install-bootloader/up.nu b/configs/crystal/install-bootloader/up.nu index 64ce9c2..0457b3e 100644 --- a/configs/crystal/install-bootloader/up.nu +++ b/configs/crystal/install-bootloader/up.nu @@ -36,6 +36,6 @@ def main [cfg] { if $cfg.preset == "GrubEfi" { install_grub_efi $cfg.location } else { - error make {msg: "Not implemented"} + todo "Implement GrubLegacy" } } diff --git a/configs/crystal/install-desktop/up.nu b/configs/crystal/install-desktop/up.nu index 13b0a23..a922b6d 100644 --- a/configs/crystal/install-desktop/up.nu +++ b/configs/crystal/install-desktop/up.nu @@ -2,4 +2,5 @@ let RUN_IN_CHROOT = true; # Applies all system changes of `install-desktop` def main [cfg] { echo "Executing up task `install-desktop` with config" $cfg + todo "Implement install desktops" } diff --git a/configs/crystal/install-flatpak/up.nu b/configs/crystal/install-flatpak/up.nu index ada0fd9..7210a64 100644 --- a/configs/crystal/install-flatpak/up.nu +++ b/configs/crystal/install-flatpak/up.nu @@ -2,4 +2,5 @@ let RUN_IN_CHROOT = true; # Applies all system changes of `install-flatpak` def main [cfg] { echo "Executing up task `install-flatpak` with config" $cfg + todo Implement install flatpak } diff --git a/src/task/commands/error.rs b/src/task/commands/error.rs new file mode 100644 index 0000000..b7a28ae --- /dev/null +++ b/src/task/commands/error.rs @@ -0,0 +1,51 @@ +use embed_nu::{ + nu_protocol::{engine::Command, Signature, SyntaxShape}, + CallExt, +}; + +#[derive(Clone)] +pub struct ErrorCommand; + +impl Command for ErrorCommand { + fn name(&self) -> &str { + "todo" + } + + fn signature(&self) -> embed_nu::nu_protocol::Signature { + Signature::new("error") + .rest("message", SyntaxShape::Any, "The error message") + .category(embed_nu::nu_protocol::Category::Custom("Tourmaline".into())) + } + + fn usage(&self) -> &str { + "Throws an error" + } + + fn run( + &self, + engine_state: &embed_nu::nu_protocol::engine::EngineState, + stack: &mut embed_nu::nu_protocol::engine::Stack, + call: &embed_nu::nu_protocol::ast::Call, + _input: embed_nu::PipelineData, + ) -> Result { + let args: Vec = call.rest(engine_state, stack, 0)?; + + if args.is_empty() { + Err(embed_nu::nu_protocol::ShellError::GenericError( + String::from("Error"), + String::from("Error"), + Some(call.span()), + None, + vec![], + )) + } else { + Err(embed_nu::nu_protocol::ShellError::GenericError( + String::from("Error"), + args.join(" "), + Some(call.span()), + None, + vec![], + )) + } + } +} diff --git a/src/task/commands/mod.rs b/src/task/commands/mod.rs index 67915d2..797b693 100644 --- a/src/task/commands/mod.rs +++ b/src/task/commands/mod.rs @@ -1,10 +1,14 @@ mod debug; +mod error; mod info; mod run; +mod todo; mod warn; mod with_cwd; pub use debug::*; +pub use error::*; pub use info::*; pub use run::*; +pub use todo::*; pub use warn::*; pub use with_cwd::*; diff --git a/src/task/commands/todo.rs b/src/task/commands/todo.rs new file mode 100644 index 0000000..6161eea --- /dev/null +++ b/src/task/commands/todo.rs @@ -0,0 +1,51 @@ +use embed_nu::{ + nu_protocol::{engine::Command, Signature, SyntaxShape}, + CallExt, +}; + +#[derive(Clone)] +pub struct TodoCommand; + +impl Command for TodoCommand { + fn name(&self) -> &str { + "todo" + } + + fn signature(&self) -> embed_nu::nu_protocol::Signature { + Signature::new("todo") + .rest("todo", SyntaxShape::Any, "Hints on what is todo") + .category(embed_nu::nu_protocol::Category::Custom("Tourmaline".into())) + } + + fn usage(&self) -> &str { + "Aborts the program as this is not implemented yet" + } + + fn run( + &self, + engine_state: &embed_nu::nu_protocol::engine::EngineState, + stack: &mut embed_nu::nu_protocol::engine::Stack, + call: &embed_nu::nu_protocol::ast::Call, + _input: embed_nu::PipelineData, + ) -> Result { + let args: Vec = call.rest(engine_state, stack, 0)?; + + if args.is_empty() { + Err(embed_nu::nu_protocol::ShellError::GenericError( + String::from("TODO"), + String::from("This is a TODO"), + Some(call.span()), + Some(String::from("Implement this functionality")), + vec![], + )) + } else { + Err(embed_nu::nu_protocol::ShellError::GenericError( + String::from("TODO"), + format!("This is a TODO: {}", args.join(" ")), + Some(call.span()), + Some(String::from("Implement this functionality")), + vec![], + )) + } + } +} diff --git a/src/task/exec_builder.rs b/src/task/exec_builder.rs index 29d241c..43557e9 100644 --- a/src/task/exec_builder.rs +++ b/src/task/exec_builder.rs @@ -6,7 +6,9 @@ use std::fs; use crate::{distro::OSConfig, error::ScriptError, utils::CFG_PATH}; use miette::{Context, IntoDiagnostic, Result}; -use super::commands::{DebugCommand, InfoCommand, RunCommand, WarnCommand, WithCwdCommand}; +use super::commands::{ + DebugCommand, ErrorCommand, InfoCommand, RunCommand, TodoCommand, WarnCommand, WithCwdCommand, +}; #[derive(Clone)] pub struct ExecBuilder { @@ -25,10 +27,12 @@ impl ExecBuilder { let mut ctx = embed_nu::Context::builder() .with_command_groups(CommandGroupConfig::default().all_groups(true))? .add_command(RunCommand)? + .add_command(ErrorCommand)? .add_command(WarnCommand)? .add_command(InfoCommand)? .add_command(DebugCommand)? .add_command(WithCwdCommand)? + .add_command(TodoCommand)? .add_env_var("PWD", std::env::var("PWD").unwrap_or(String::from("/"))) .add_env_var( "PATH", diff --git a/src/utils.rs b/src/utils.rs index ef654a6..1a8791a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -42,6 +42,7 @@ pub async fn generate_script_files>(output: P) -> Result<()> { r#"# Applies all system changes of `{name}` def main [cfg] {{ echo "Executing up task `{name}` with config" $cfg + todo "Implement me" }} "# ), @@ -56,6 +57,7 @@ def main [cfg] {{ r#"# Reverts all system changes of `{name}` def main [cfg] {{ echo "Executing up task `{name}` with config" $cfg + todo "Implement me" }} "# )