ggen_cli_lib/cmds/
help_progressive.rs

1//! Progressive help system that adapts to user experience level
2
3use clap::Args;
4use colored::Colorize;
5use ggen_utils::error::Result;
6use ggen_utils::user_level::{ProgressiveHelp, UserActivity};
7
8#[derive(Args, Debug)]
9pub struct HelpProgressiveArgs {
10    /// Command to get help for
11    #[arg(value_name = "COMMAND")]
12    pub command: Option<String>,
13
14    /// Show tips based on your usage patterns
15    #[arg(long)]
16    pub tips: bool,
17}
18
19pub async fn run(args: &HelpProgressiveArgs) -> Result<()> {
20    let activity = UserActivity::load().unwrap_or_default();
21    let level = activity.get_level();
22
23    println!();
24    println!(
25        "{} {} {}",
26        "📚".cyan(),
27        "Your level:".bold(),
28        level.as_str().green().bold()
29    );
30    println!(
31        "   {} {}",
32        "Commands run:".dimmed(),
33        activity.total_commands.to_string().cyan()
34    );
35    println!();
36
37    if args.tips {
38        // Show contextual tips
39        let tips = ProgressiveHelp::get_contextual_tips(&activity);
40        if !tips.is_empty() {
41            println!("{}", "💡 Tips for you:".yellow().bold());
42            for tip in tips {
43                println!("   {}", tip);
44            }
45            println!();
46        }
47
48        // Show next suggested command
49        if let Some(suggestion) =
50            ProgressiveHelp::suggest_next_command(activity.last_command.as_deref(), level)
51        {
52            println!("{} {}", "🎯 Suggested next:".green().bold(), suggestion);
53            println!();
54        }
55
56        // Show most used commands
57        let top_commands = activity.get_top_commands(3);
58        if !top_commands.is_empty() {
59            println!("{}", "🔝 Your most used commands:".blue().bold());
60            for (i, (cmd, count)) in top_commands.iter().enumerate() {
61                println!("   {}. {} ({} times)", i + 1, cmd.cyan(), count);
62            }
63            println!();
64        }
65    } else if let Some(command) = &args.command {
66        // Show help for specific command
67        let help_text = ProgressiveHelp::get_command_help(command, level);
68        println!("{} {}", "Help for".bold(), command.cyan().bold());
69        println!();
70        println!("{}", help_text);
71        println!();
72    } else {
73        // Show general help adapted to level
74        match level {
75            ggen_utils::user_level::UserLevel::Newcomer => {
76                println!("{}", "🚀 Welcome to ggen!".green().bold());
77                println!();
78                println!("Here are the essential commands to get started:");
79                println!();
80                println!("  {} - Check if your environment is ready", "ggen doctor".cyan());
81                println!(
82                    "  {} - Generate a demo project",
83                    "ggen quickstart demo".cyan()
84                );
85                println!("  {} - See available templates", "ggen list".cyan());
86                println!(
87                    "  {} - Generate from a template",
88                    "ggen gen <template>".cyan()
89                );
90                println!();
91                println!(
92                    "💡 Tip: Run '{}' to see all commands",
93                    "ggen --help".yellow()
94                );
95            }
96            ggen_utils::user_level::UserLevel::Intermediate => {
97                println!("{}", "🎯 Common Workflows".green().bold());
98                println!();
99                println!("Now that you know the basics, try these workflows:");
100                println!();
101                println!(
102                    "  {} - Find templates by description",
103                    "ggen search <query>".cyan()
104                );
105                println!(
106                    "  {} - Install a template package",
107                    "ggen add <package>".cyan()
108                );
109                println!(
110                    "  {} - AI-powered code generation",
111                    "ggen ai generate".cyan()
112                );
113                println!(
114                    "  {} - Create a full project",
115                    "ggen ai project \"idea\"".cyan()
116                );
117                println!();
118            }
119            ggen_utils::user_level::UserLevel::Advanced => {
120                println!("{}", "⚡ Advanced Features".green().bold());
121                println!();
122                println!("Explore these advanced capabilities:");
123                println!();
124                println!(
125                    "  {} - Project lifecycle management",
126                    "ggen lifecycle".cyan()
127                );
128                println!(
129                    "  {} - RDF graph generation",
130                    "ggen ai graph".cyan()
131                );
132                println!(
133                    "  {} - SPARQL query generation",
134                    "ggen ai sparql".cyan()
135                );
136                println!(
137                    "  {} - GitHub integration",
138                    "ggen github".cyan()
139                );
140                println!();
141            }
142            ggen_utils::user_level::UserLevel::Expert => {
143                println!("{}", "🚀 Power User Mode".green().bold());
144                println!();
145                println!("You're an expert! Here are some pro tips:");
146                println!();
147                println!("  • Create custom templates with RDF + SPARQL");
148                println!("  • Use injection modes for idempotent updates");
149                println!("  • Leverage deterministic generation for testing");
150                println!("  • Integrate ggen into CI/CD pipelines");
151                println!();
152                println!("Consider contributing your templates to the marketplace!");
153            }
154        }
155        println!();
156    }
157
158    Ok(())
159}