|
1 | 1 | using System.CommandLine; |
2 | | -using Flow.AI.Core.Models; |
3 | 2 | using PromptStream.AI.CLI.Commands; |
| 3 | +using PromptStream.AI.CLI.Utils; |
4 | 4 |
|
5 | 5 | namespace PromptStream.AI.CLI |
6 | 6 | { |
7 | | - internal class Program |
| 7 | + internal static class Program |
8 | 8 | { |
9 | | - static async Task<int> Main(string[] args) |
| 9 | + public static async Task<int> Main(string[] args) |
10 | 10 | { |
11 | | - var root = new RootCommand("PromptStream.AI CLI — build, validate, generate, and manage prompt contexts."); |
| 11 | + // Root command description |
| 12 | + var root = new RootCommand("PromptStream.AI CLI — Build, validate, analyze, and generate prompts interactively."); |
12 | 13 |
|
13 | | - // Register modular commands |
| 14 | + // Register all subcommands |
14 | 15 | root.AddCommand(BuildCommand.Create()); |
15 | 16 | root.AddCommand(ValidateCommand.Create()); |
16 | 17 | root.AddCommand(GenerateCommand.Create()); |
17 | | - root.AddCommand(ContextCommand.Create()); |
18 | 18 | root.AddCommand(AnalyzeCommand.Create()); |
| 19 | + root.AddCommand(ContextCommand.Create()); |
| 20 | + |
| 21 | + // Global verbose flag (optional, can be used later) |
| 22 | + var verboseOpt = new Option<bool>( |
| 23 | + aliases: new[] { "-v", "--verbose" }, |
| 24 | + description: "Enable verbose output"); |
| 25 | + root.AddGlobalOption(verboseOpt); |
| 26 | + |
| 27 | + // Default handler: print help if no command is given |
| 28 | + root.SetHandler(() => |
| 29 | + { |
| 30 | + ConsoleFormatter.Info("PromptStream.AI CLI — available commands:"); |
| 31 | + Console.WriteLine(" build Render a prompt with variable substitution"); |
| 32 | + Console.WriteLine(" validate Validate structure and token usage"); |
| 33 | + Console.WriteLine(" analyze Analyze cost and token metrics"); |
| 34 | + Console.WriteLine(" generate Build, validate, and run a model response"); |
| 35 | + Console.WriteLine(" context Manage and summarize conversation context"); |
| 36 | + Console.WriteLine("\nUse '--help' with any command for details."); |
| 37 | + }); |
19 | 38 |
|
20 | 39 | return await root.InvokeAsync(args); |
21 | 40 | } |
22 | 41 |
|
23 | 42 | /// <summary> |
24 | | - /// Loads a prompt template and key-value variables from CLI input. |
| 43 | + /// Utility to load a prompt template and variable map. |
| 44 | + /// Used by Build, Validate, Generate, and Analyze commands. |
25 | 45 | /// </summary> |
26 | | - internal static (PromptTemplate, Dictionary<string, string>) LoadTemplateAndVars(string template, string[] vars) |
| 46 | + public static (string promptTemplate, Dictionary<string, string> variableMap) LoadTemplateAndVars(string templatePathOrText, string[]? vars) |
27 | 47 | { |
28 | | - string content = File.Exists(template) |
29 | | - ? File.ReadAllText(template) |
30 | | - : template; |
| 48 | + string promptTemplate; |
31 | 49 |
|
32 | | - var variableMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); |
33 | | - foreach (var v in vars ?? Array.Empty<string>()) |
| 50 | + // Try to treat the input as a file path first |
| 51 | + if (File.Exists(templatePathOrText)) |
34 | 52 | { |
35 | | - var parts = v.Split('=', 2); |
36 | | - if (parts.Length == 2) |
37 | | - variableMap[parts[0]] = parts[1]; |
| 53 | + promptTemplate = File.ReadAllText(templatePathOrText); |
| 54 | + } |
| 55 | + else |
| 56 | + { |
| 57 | + // Otherwise treat as inline text |
| 58 | + promptTemplate = templatePathOrText; |
38 | 59 | } |
39 | 60 |
|
40 | | - var promptTemplate = new PromptTemplate |
| 61 | + var variableMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); |
| 62 | + |
| 63 | + if (vars != null) |
41 | 64 | { |
42 | | - Id = Path.GetFileNameWithoutExtension(template) ?? "inline-template", |
43 | | - Template = content |
44 | | - }; |
| 65 | + foreach (var v in vars) |
| 66 | + { |
| 67 | + var parts = v.Split('=', 2); |
| 68 | + if (parts.Length == 2) |
| 69 | + variableMap[parts[0].Trim()] = parts[1].Trim(); |
| 70 | + } |
| 71 | + } |
45 | 72 |
|
46 | 73 | return (promptTemplate, variableMap); |
47 | 74 | } |
|
0 commit comments