ricecoder_cli/commands/
help.rs

1// Help and tutorial command
2
3use super::Command;
4use crate::error::CliResult;
5use crate::output::OutputStyle;
6
7/// Help and tutorial command
8pub struct HelpCommand {
9    pub topic: Option<String>,
10}
11
12impl HelpCommand {
13    pub fn new(topic: Option<String>) -> Self {
14        Self { topic }
15    }
16
17    fn show_main_help(&self) {
18        let style = OutputStyle::default();
19        println!("{}", style.section("RiceCoder - Spec-Driven Code Generation"));
20        println!();
21        println!("RiceCoder is a terminal-first, spec-driven coding assistant that helps you");
22        println!("write better code through research-first project analysis and AI-powered generation.");
23        println!();
24
25        println!("{}", style.section("Quick Start"));
26        println!();
27        println!("{}", style.numbered_item(1, "Initialize a new project"));
28        println!("   rice init");
29        println!();
30        println!("{}", style.numbered_item(2, "Create a specification"));
31        println!("   Create a file with your requirements and design");
32        println!();
33        println!("{}", style.numbered_item(3, "Generate code"));
34        println!("   rice gen --spec my-spec.md");
35        println!();
36
37        println!("{}", style.section("Available Commands"));
38        println!();
39        println!("{}", style.key_value("init", "Initialize a new ricecoder project"));
40        println!("{}", style.key_value("gen", "Generate code from specifications"));
41        println!("{}", style.key_value("chat", "Interactive chat mode"));
42        println!("{}", style.key_value("config", "Manage configuration"));
43        println!("{}", style.key_value("lsp", "Start LSP server"));
44        println!("{}", style.key_value("help", "Show this help message"));
45        println!();
46
47        println!("{}", style.section("Getting Help"));
48        println!();
49        println!("For help on a specific command:");
50        println!("   rice help <command>");
51        println!();
52        println!("For tutorials:");
53        println!("   rice help tutorial");
54        println!();
55        println!("For common issues:");
56        println!("   rice help troubleshooting");
57        println!();
58        println!("For keyboard shortcuts:");
59        println!("   rice help shortcuts");
60        println!();
61        println!("For accessibility features:");
62        println!("   rice help accessibility");
63        println!();
64
65        println!("{}", style.section("Resources"));
66        println!();
67        println!("{}", style.link("Documentation", "https://ricecoder.dev/docs"));
68        println!("{}", style.link("Examples", "https://ricecoder.dev/examples"));
69        println!("{}", style.link("GitHub", "https://github.com/ricecoder/ricecoder"));
70        println!();
71    }
72
73    fn show_command_help(&self, command: &str) {
74        use crate::accessibility::{AccessibilityFeatures, KeyboardShortcuts};
75        
76        let style = OutputStyle::default();
77        match command {
78            "shortcuts" => {
79                KeyboardShortcuts::print_all();
80                return;
81            }
82            "accessibility" => {
83                AccessibilityFeatures::print_guide();
84                return;
85            }
86            "init" => {
87                println!("{}", style.section("rice init - Initialize a Project"));
88                println!();
89                println!("Initialize a new RiceCoder project with interactive setup.");
90                println!();
91                println!("{}", style.header("Usage"));
92                println!("   rice init [PATH]");
93                println!();
94                println!("{}", style.header("Arguments"));
95                println!("{}", style.key_value("PATH", "Project directory (default: current)"));
96                println!();
97                println!("{}", style.header("What it does"));
98                println!("{}", style.list_item("Creates .agent/ directory"));
99                println!("{}", style.list_item("Generates ricecoder.toml configuration"));
100                println!("{}", style.list_item("Creates example specification"));
101                println!("{}", style.list_item("Creates README.md"));
102                println!();
103                println!("{}", style.header("Example"));
104                println!("   rice init my-project");
105                println!();
106            }
107            "gen" => {
108                println!("{}", style.section("rice gen - Generate Code"));
109                println!();
110                println!("Generate code from specifications using AI.");
111                println!();
112                println!("{}", style.header("Usage"));
113                println!("   rice gen --spec <FILE>");
114                println!();
115                println!("{}", style.header("Options"));
116                println!("{}", style.key_value("--spec FILE", "Specification file to use"));
117                println!("{}", style.key_value("--provider", "AI provider to use"));
118                println!("{}", style.key_value("--output", "Output directory"));
119                println!();
120                println!("{}", style.header("Example"));
121                println!("   rice gen --spec my-spec.md");
122                println!();
123            }
124            "chat" => {
125                println!("{}", style.section("rice chat - Interactive Chat"));
126                println!();
127                println!("Start an interactive chat session with RiceCoder.");
128                println!();
129                println!("{}", style.header("Usage"));
130                println!("   rice chat [MESSAGE]");
131                println!();
132                println!("{}", style.header("Arguments"));
133                println!("{}", style.key_value("MESSAGE", "Initial message (optional)"));
134                println!();
135                println!("{}", style.header("Commands in chat"));
136                println!("{}", style.key_value("/exit", "Exit chat mode"));
137                println!("{}", style.key_value("/help", "Show chat help"));
138                println!("{}", style.key_value("/clear", "Clear chat history"));
139                println!();
140                println!("{}", style.header("Example"));
141                println!("   rice chat");
142                println!("   rice chat \"How do I create a REST API?\"");
143                println!();
144            }
145            "config" => {
146                println!("{}", style.section("rice config - Manage Configuration"));
147                println!();
148                println!("View and manage RiceCoder configuration.");
149                println!();
150                println!("{}", style.header("Usage"));
151                println!("   rice config [ACTION]");
152                println!();
153                println!("{}", style.header("Actions"));
154                println!("{}", style.key_value("show", "Show current configuration"));
155                println!("{}", style.key_value("set", "Set a configuration value"));
156                println!("{}", style.key_value("get", "Get a configuration value"));
157                println!();
158                println!("{}", style.header("Example"));
159                println!("   rice config show");
160                println!("   rice config set providers.default anthropic");
161                println!();
162            }
163            _ => {
164                println!("{}", style.error(&format!("Unknown command: {}", command)));
165                println!();
166                println!("Run 'rice help' for available commands.");
167            }
168        }
169    }
170
171    fn show_tutorial(&self) {
172        let style = OutputStyle::default();
173        println!("{}", style.section("RiceCoder Tutorial"));
174        println!();
175
176        println!("{}", style.header("1. Getting Started"));
177        println!();
178        println!("First, initialize a new project:");
179        println!("   rice init my-project");
180        println!();
181        println!("This creates:");
182        println!("{}", style.list_item(".agent/ricecoder.toml - Configuration"));
183        println!("{}", style.list_item(".agent/example-spec.md - Example specification"));
184        println!("{}", style.list_item("README.md - Project documentation"));
185        println!();
186
187        println!("{}", style.header("2. Create a Specification"));
188        println!();
189        println!("Create a file with your requirements and design:");
190        println!();
191        println!("   # my-feature.md");
192        println!("   ## Requirements");
193        println!("   - User can create tasks");
194        println!("   - Tasks are persisted to storage");
195        println!();
196        println!("   ## Design");
197        println!("   - Use SQLite for storage");
198        println!("   - REST API for task management");
199        println!();
200
201        println!("{}", style.header("3. Generate Code"));
202        println!();
203        println!("Generate code from your specification:");
204        println!("   rice gen --spec my-feature.md");
205        println!();
206        println!("RiceCoder will:");
207        println!("{}", style.list_item("Analyze your specification"));
208        println!("{}", style.list_item("Generate code based on requirements"));
209        println!("{}", style.list_item("Create tests"));
210        println!("{}", style.list_item("Generate documentation"));
211        println!();
212
213        println!("{}", style.header("4. Review and Refine"));
214        println!();
215        println!("Review the generated code and refine as needed:");
216        println!("   rice chat \"How can I improve this code?\"");
217        println!();
218
219        println!("{}", style.header("5. Deploy"));
220        println!();
221        println!("Once satisfied, deploy your code:");
222        println!("   git add .");
223        println!("   git commit -m \"Add generated feature\"");
224        println!("   git push");
225        println!();
226
227        println!("{}", style.section("Tips & Tricks"));
228        println!();
229        println!("{}", style.tip("Use detailed specifications for better results"));
230        println!("{}", style.tip("Include examples in your requirements"));
231        println!("{}", style.tip("Review generated code before using"));
232        println!("{}", style.tip("Use chat mode for interactive refinement"));
233        println!();
234
235        println!("{}", style.section("Learn More"));
236        println!();
237        println!("{}", style.link("Full Documentation", "https://ricecoder.dev/docs"));
238        println!("{}", style.link("Examples", "https://ricecoder.dev/examples"));
239        println!("{}", style.link("Best Practices", "https://ricecoder.dev/docs/best-practices"));
240        println!();
241    }
242
243    fn show_troubleshooting(&self) {
244        let style = OutputStyle::default();
245        println!("{}", style.section("Troubleshooting"));
246        println!();
247
248        println!("{}", style.header("Common Issues"));
249        println!();
250
251        println!("{}", style.header("Q: \"Provider error: Invalid API key\""));
252        println!();
253        println!("A: Check your API key configuration:");
254        println!("   1. Run: rice config show");
255        println!("   2. Verify your API key is set correctly");
256        println!("   3. Check: https://ricecoder.dev/docs/providers");
257        println!();
258
259        println!("{}", style.header("Q: \"Configuration error: File not found\""));
260        println!();
261        println!("A: Initialize your project first:");
262        println!("   rice init");
263        println!();
264
265        println!("{}", style.header("Q: \"Generation failed: Invalid specification\""));
266        println!();
267        println!("A: Check your specification format:");
268        println!("   1. Review the example: .agent/example-spec.md");
269        println!("   2. Ensure all required sections are present");
270        println!("   3. Check: https://ricecoder.dev/docs/specifications");
271        println!();
272
273        println!("{}", style.header("Q: \"Network error: Connection refused\""));
274        println!();
275        println!("A: Check your network connection:");
276        println!("   1. Verify internet connectivity");
277        println!("   2. Check firewall settings");
278        println!("   3. Try again later if provider is down");
279        println!();
280
281        println!("{}", style.section("Getting Help"));
282        println!();
283        println!("If you can't find the answer:");
284        println!();
285        println!("{}", style.list_item("Check the documentation: https://ricecoder.dev/docs"));
286        println!("{}", style.list_item("Search GitHub issues: https://github.com/ricecoder/ricecoder/issues"));
287        println!("{}", style.list_item("Ask in discussions: https://github.com/ricecoder/ricecoder/discussions"));
288        println!();
289    }
290}
291
292impl Command for HelpCommand {
293    fn execute(&self) -> CliResult<()> {
294        match &self.topic {
295            None => self.show_main_help(),
296            Some(topic) => match topic.as_str() {
297                "tutorial" => self.show_tutorial(),
298                "troubleshooting" => self.show_troubleshooting(),
299                _ => self.show_command_help(topic),
300            },
301        }
302        Ok(())
303    }
304}