From f3a2940e70dea2c35dcae3fca019e94bf8758b4d Mon Sep 17 00:00:00 2001 From: Taeer Bar-Yam Date: Tue, 15 Feb 2022 11:50:14 -0500 Subject: [PATCH 1/2] add descriptive output when creating templates this includes a `welcomeText` attribute which can be set in the template, as well as outputing which files were created. --- src/nix/flake-init.md | 8 ++++++++ src/nix/flake.cc | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/nix/flake-init.md b/src/nix/flake-init.md index 890038016..c8bcee375 100644 --- a/src/nix/flake-init.md +++ b/src/nix/flake-init.md @@ -37,6 +37,10 @@ A flake can declare templates through its `templates` and * `path`: The path of the directory to be copied. +* `welcomeText`: A block of text to display when a user initializes a new flake + based on this template. + + Here is an example: ``` @@ -45,6 +49,10 @@ outputs = { self }: { templates.rust = { path = ./rust; description = "A simple Rust/Cargo project"; + welcomeText = '' + You've created a simple Rust/Cargo template. + Visit https://www.rust-lang.org/ for more info. + ''; }; templates.defaultTemplate = self.templates.rust; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 4bc79820c..f5d34c10f 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -728,6 +728,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand else throw Error("file '%s' has unsupported type", from2); files.push_back(to2); + notice("wrote: %s", to2); } }; @@ -738,6 +739,11 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand for (auto & s : files) args.push_back(s); runProgram("git", true, args); } + auto welcomeText = cursor->maybeGetAttr("welcomeText"); + if (welcomeText) { + notice("\n----------\n"); + notice(welcomeText->getString()); + } } }; From f56dd3a36bc8a325028588fd5500cbc33fa48a26 Mon Sep 17 00:00:00 2001 From: Taeer Bar-Yam Date: Thu, 17 Feb 2022 13:59:32 -0500 Subject: [PATCH 2/2] make flake template welcomeText markdown --- src/nix/flake-init.md | 14 ++++++++++---- src/nix/flake.cc | 5 +++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/nix/flake-init.md b/src/nix/flake-init.md index c8bcee375..c13b22248 100644 --- a/src/nix/flake-init.md +++ b/src/nix/flake-init.md @@ -37,8 +37,8 @@ A flake can declare templates through its `templates` and * `path`: The path of the directory to be copied. -* `welcomeText`: A block of text to display when a user initializes a new flake - based on this template. +* `welcomeText`: A block of markdown text to display when a user initializes a + new flake based on this template. Here is an example: @@ -50,8 +50,14 @@ outputs = { self }: { path = ./rust; description = "A simple Rust/Cargo project"; welcomeText = '' - You've created a simple Rust/Cargo template. - Visit https://www.rust-lang.org/ for more info. + # Simple Rust/Cargo Template + ## Intended usage + The intended usage of this flake is... + + ## More info + - [Rust language](https://www.rust-lang.org/) + - [Rust on the NixOS Wiki](https://nixos.wiki/wiki/Rust) + - ... ''; }; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index f5d34c10f..ac14bed74 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -13,6 +13,7 @@ #include "registry.hh" #include "json.hh" #include "eval-cache.hh" +#include "markdown.hh" #include #include @@ -741,8 +742,8 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand } auto welcomeText = cursor->maybeGetAttr("welcomeText"); if (welcomeText) { - notice("\n----------\n"); - notice(welcomeText->getString()); + notice("\n"); + notice(renderMarkdownToTerminal(welcomeText->getString())); } } };