1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
use clap::Parser;
use mullvad_api::ApiEndpoint;
use mullvad_problem_report::{Error, collect_report};
use std::{
env,
path::{Path, PathBuf},
process,
};
use talpid_types::ErrorExt;
fn main() {
process::exit(match run() {
Ok(()) => 0,
Err(error) => {
eprintln!("{}", error.display_chain());
1
}
})
}
#[derive(Debug, Parser)]
#[command(author, version = mullvad_version::VERSION, about, long_about = None)]
#[command(
arg_required_else_help = true,
disable_help_subcommand = true,
disable_version_flag = true
)]
enum Cli {
/// Collect problem report to a single file
Collect {
/// The destination path for saving the collected report
#[arg(required = true, long, short = 'o')]
output: PathBuf,
/// Paths to additional log files to be included
extra_logs: Vec<PathBuf>,
/// List of strings to remove from the report
#[arg(long)]
redact: Vec<String>,
},
/// Send collected problem report
Send {
/// Path to a previously collected report file
#[arg(required = true, long, short = 'r')]
report: PathBuf,
/// Email to attach to the problem report
#[arg(long, short = 'e')]
email: Option<String>,
/// Message to include in the problem report
#[arg(long, short = 'm')]
message: Option<String>,
},
}
fn run() -> Result<(), Error> {
env_logger::init();
match Cli::parse() {
Cli::Collect {
output,
extra_logs,
redact,
} => {
collect_report(&extra_logs, &output, redact)?;
println!("Problem report written to {}", output.display());
println!();
println!("Send the problem report to support via the send subcommand. See:");
println!(" $ {} send --help", env::args().next().unwrap());
}
Cli::Send {
report,
email,
message,
} => {
send_problem_report(
&email.unwrap_or_default(),
&message.unwrap_or_default(),
None,
&report,
)?;
}
}
Ok(())
}
fn send_problem_report(
user_email: &str,
user_message: &str,
account_token: Option<&str>,
report_path: &Path,
) -> Result<(), Error> {
let cache_dir = mullvad_paths::get_cache_dir().map_err(Error::ObtainCacheDirectory)?;
mullvad_problem_report::send_problem_report(
user_email,
user_message,
account_token,
report_path,
&cache_dir,
ApiEndpoint::from_env_vars(),
)
.inspect_err(|error| {
eprintln!("{}", error.display_chain());
})?;
println!("Problem report sent");
Ok(())
}
|