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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use super::{Executable, default_tracing};
use clap::Subcommand;
use eyre::{Context, bail};
#[derive(Debug, Subcommand)]
/// Dora CLI self-management commands
pub enum SelfSubCommand {
/// Check for updates or update the CLI
Update {
/// Only check for updates without installing
#[clap(long)]
check_only: bool,
},
/// Remove The Dora CLI from the system
Uninstall {
/// Force uninstallation without confirmation
#[clap(long)]
force: bool,
},
}
impl Executable for SelfSubCommand {
async fn execute(self) -> eyre::Result<()> {
default_tracing()?;
match self {
SelfSubCommand::Update { check_only } => {
println!("Checking for updates...");
#[cfg(target_os = "linux")]
let bin_path_in_archive = format!("dora-cli-{}/dora", env!("TARGET"));
#[cfg(target_os = "macos")]
let bin_path_in_archive = format!("dora-cli-{}/dora", env!("TARGET"));
#[cfg(target_os = "windows")]
let bin_path_in_archive = String::from("dora.exe");
let status = self_update::backends::github::Update::configure()
.repo_owner("dora-rs")
.repo_name("dora")
.bin_path_in_archive(&bin_path_in_archive)
.bin_name("dora")
.show_download_progress(true)
.current_version(env!("CARGO_PKG_VERSION"))
.build()?;
if check_only {
// Only check if an update is available
match status.get_latest_release() {
Ok(release) => {
let current_version = self_update::cargo_crate_version!();
if current_version != release.version {
println!(
"An update is available: {}. Run 'dora self update' to update",
release.version
);
} else {
println!(
"Dora CLI is already at the latest version: {current_version}"
);
}
}
Err(e) => println!("Failed to check for updates: {e}"),
}
} else {
// Perform the actual update
match status.update() {
Ok(update_status) => match update_status {
self_update::Status::UpToDate(version) => {
println!("Dora CLI is already at the latest version: {version}");
}
self_update::Status::Updated(version) => {
println!("Successfully updated Dora CLI to version: {version}");
}
},
Err(e) => println!("Failed to update: {e}"),
}
}
}
SelfSubCommand::Uninstall { force } => {
if !force {
let confirmed =
inquire::Confirm::new("Are you sure you want to uninstall Dora CLI?")
.with_default(false)
.prompt()
.wrap_err("Uninstallation cancelled")?;
if !confirmed {
println!("Uninstallation cancelled");
return Ok(());
}
}
println!("Uninstalling Dora CLI...");
#[cfg(feature = "python")]
{
println!("Detected Python installation...");
// Try uv pip uninstall first
let uv_status = std::process::Command::new("uv")
.args(["pip", "uninstall", "dora-rs-cli"])
.status();
if let Ok(status) = uv_status {
if status.success() {
println!("Dora CLI has been successfully uninstalled via uv pip.");
return Ok(());
}
}
// Fall back to regular pip uninstall
println!("Trying with pip...");
let status = std::process::Command::new("pip")
.args(["uninstall", "-y", "dora-rs-cli"])
.status()
.wrap_err("Failed to run pip uninstall")?;
if status.success() {
println!("Dora CLI has been successfully uninstalled via pip.");
} else {
bail!("Failed to uninstall Dora CLI via pip.");
}
}
#[cfg(not(feature = "python"))]
{
match self_replace::self_delete() {
Ok(_) => {
println!("Dora CLI has been successfully uninstalled.");
}
Err(e) => {
bail!("Failed to uninstall Dora CLI: {}", e);
}
}
}
}
}
Ok(())
}
}