Rust · 2758 bytes Raw Blame History
1 //! WANDA CLI - WeMod launcher for Linux
2
3 mod commands;
4
5 use clap::{Parser, Subcommand};
6 use std::path::PathBuf;
7 use tracing_subscriber::{fmt, prelude::*, EnvFilter};
8
9 #[derive(Parser)]
10 #[command(name = "wanda")]
11 #[command(author = "WANDA Contributors")]
12 #[command(version)]
13 #[command(about = "WeMod launcher for Linux", long_about = None)]
14 struct Cli {
15 /// Increase verbosity (-v, -vv, -vvv)
16 #[arg(short, long, action = clap::ArgAction::Count, global = true)]
17 verbose: u8,
18
19 /// Suppress non-essential output
20 #[arg(short, long, global = true)]
21 quiet: bool,
22
23 /// Output in JSON format
24 #[arg(long, global = true)]
25 json: bool,
26
27 /// Use a custom config file
28 #[arg(long, global = true)]
29 config: Option<PathBuf>,
30
31 #[command(subcommand)]
32 command: Commands,
33 }
34
35 #[derive(Subcommand)]
36 enum Commands {
37 /// Initialize WANDA and set up WeMod prefix
38 Init(commands::init::InitArgs),
39
40 /// Scan for Steam games
41 Scan(commands::scan::ScanArgs),
42
43 /// Launch a game with WeMod
44 Launch(commands::launch::LaunchArgs),
45
46 /// Manage Wine/Proton prefixes
47 #[command(subcommand)]
48 Prefix(commands::prefix::PrefixCommands),
49
50 /// Manage WeMod installation
51 #[command(subcommand)]
52 Wemod(commands::wemod::WemodCommands),
53
54 /// Manage configuration
55 #[command(subcommand)]
56 Config(commands::config::ConfigCommands),
57
58 /// Diagnose issues and generate reports
59 Doctor(commands::doctor::DoctorArgs),
60 }
61
62 fn setup_logging(verbose: u8, quiet: bool) {
63 let filter = if quiet {
64 "warn"
65 } else {
66 match verbose {
67 0 => "info",
68 1 => "debug",
69 _ => "trace",
70 }
71 };
72
73 let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(filter));
74
75 tracing_subscriber::registry()
76 .with(fmt::layer().with_target(false).without_time())
77 .with(filter)
78 .init();
79 }
80
81 #[tokio::main]
82 async fn main() {
83 let cli = Cli::parse();
84
85 setup_logging(cli.verbose, cli.quiet);
86
87 let result = match cli.command {
88 Commands::Init(args) => commands::init::run(args, cli.config).await,
89 Commands::Scan(args) => commands::scan::run(args, cli.config).await,
90 Commands::Launch(args) => commands::launch::run(args, cli.config).await,
91 Commands::Prefix(cmd) => commands::prefix::run(cmd, cli.config).await,
92 Commands::Wemod(cmd) => commands::wemod::run(cmd, cli.config).await,
93 Commands::Config(cmd) => commands::config::run(cmd, cli.config).await,
94 Commands::Doctor(args) => commands::doctor::run(args, cli.config).await,
95 };
96
97 if let Err(e) = result {
98 eprintln!("Error: {}", e.user_message());
99 std::process::exit(1);
100 }
101 }
102