From cd6ebf72951b62adae0dd2ad61cf3dfb99797860 Mon Sep 17 00:00:00 2001
From: Marcus Schiesser <mail@marcusschiesser.de>
Date: Tue, 4 Jun 2024 12:20:52 +0200
Subject: [PATCH] dx: add hint if tool config is needed

---
 helpers/tools.ts | 8 +++++++-
 questions.ts     | 8 ++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/helpers/tools.ts b/helpers/tools.ts
index 501b320b..e4502011 100644
--- a/helpers/tools.ts
+++ b/helpers/tools.ts
@@ -173,9 +173,15 @@ export const getTools = (toolsName: string[]): Tool[] => {
   return tools;
 };
 
+export const toolRequiresConfig = (tool: Tool): boolean => {
+  const hasConfig = Object.keys(tool.config || {}).length > 0;
+  const hasEmptyEnvVar = tool.envVars?.some((envVar) => !envVar.value) ?? false;
+  return hasConfig || hasEmptyEnvVar;
+};
+
 export const toolsRequireConfig = (tools?: Tool[]): boolean => {
   if (tools) {
-    return tools?.some((tool) => Object.keys(tool.config || {}).length > 0);
+    return tools?.some(toolRequiresConfig);
   }
   return false;
 };
diff --git a/questions.ts b/questions.ts
index 8d1f07dd..8e873dac 100644
--- a/questions.ts
+++ b/questions.ts
@@ -16,7 +16,11 @@ import { templatesDir } from "./helpers/dir";
 import { getAvailableLlamapackOptions } from "./helpers/llama-pack";
 import { askModelConfig } from "./helpers/providers";
 import { getProjectOptions } from "./helpers/repo";
-import { supportedTools, toolsRequireConfig } from "./helpers/tools";
+import {
+  supportedTools,
+  toolRequiresConfig,
+  toolsRequireConfig,
+} from "./helpers/tools";
 
 export type QuestionArgs = Omit<
   InstallAppArgs,
@@ -652,7 +656,7 @@ export const askQuestions = async (
         t.supportedFrameworks?.includes(program.framework),
       );
       const toolChoices = options.map((tool) => ({
-        title: tool.display,
+        title: `${tool.display}${toolRequiresConfig(tool) ? "" : " (no config needed)"}`,
         value: tool.name,
       }));
       const { toolsName } = await prompts({
-- 
GitLab