Skip to content

Commit ac361dc

Browse files
committed
Rename --host to --remote-host
1 parent bcb6d62 commit ac361dc

9 files changed

Lines changed: 68 additions & 50 deletions

File tree

packages/cli-rust/src/commands/cleanup.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use anyhow::{Context, Result, bail};
44
use opencode_cloud_core::config::{Config, get_config_path, load_config_or_default};
55
use opencode_cloud_core::docker::ParsedMount;
6-
use opencode_cloud_core::load_hosts;
76
use std::fs;
87
use std::path::{Component, Path, PathBuf};
98

@@ -25,20 +24,8 @@ impl MountCleanupResult {
2524
}
2625
}
2726

28-
pub fn resolve_target_host_name(maybe_host: Option<&str>) -> Option<String> {
29-
if let Some(name) = maybe_host {
30-
return Some(name.to_string());
31-
}
32-
33-
let hosts = load_hosts().unwrap_or_default();
34-
hosts.default_host.clone()
35-
}
36-
3727
pub fn is_remote_host(maybe_host: Option<&str>) -> bool {
38-
matches!(
39-
resolve_target_host_name(maybe_host),
40-
Some(name) if !name.is_empty() && name != "local"
41-
)
28+
matches!(maybe_host, Some(name) if !name.is_empty())
4229
}
4330

4431
pub fn load_config_for_mounts(include_defaults_if_missing: bool) -> Result<(Config, bool)> {

packages/cli-rust/src/commands/host/default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub async fn cmd_host_default(args: &HostDefaultArgs, quiet: bool, _verbose: u8)
7575
" {} Commands will now target {} unless {} is specified.",
7676
style("Note:").dim(),
7777
style(name).cyan(),
78-
style("--host").yellow()
78+
style("--remote-host or --local").yellow()
7979
);
8080
}
8181
Ok(())

packages/cli-rust/src/commands/mount/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub async fn cmd_mount_clean(
3030
if is_remote_host(maybe_host) {
3131
return Err(anyhow!(
3232
"Mount cleanup is only supported for local hosts.\n\
33-
Run without --host or use --host local on the machine where the mounts exist."
33+
Run without --remote-host or use --local on the machine where the mounts exist."
3434
));
3535
}
3636

packages/cli-rust/src/commands/reset/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async fn cmd_reset_container(
103103
if (args.clean_mounts || args.purge_mounts) && is_remote_host(maybe_host) {
104104
bail!(
105105
"Mount cleanup is only supported for local hosts.\n\
106-
Run without --host or use --host local on the machine where the mounts exist."
106+
Run without --remote-host or use --local on the machine where the mounts exist."
107107
);
108108
}
109109

@@ -263,7 +263,7 @@ async fn cmd_reset_host(
263263
if is_remote_host(maybe_host) {
264264
bail!(
265265
"Host reset is only supported on the local machine.\n\
266-
Run without --host or use --host local."
266+
Run without --remote-host or use --local."
267267
);
268268
}
269269

packages/cli-rust/src/commands/setup.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@ pub struct SetupArgs {
2525
pub bootstrap: bool,
2626

2727
/// Run setup for a remote host instead of local Docker
28-
#[arg(long)]
29-
pub host: Option<String>,
28+
#[arg(long, conflicts_with = "local")]
29+
pub remote_host: Option<String>,
30+
31+
/// Force local Docker (ignores default_host)
32+
#[arg(long, conflicts_with = "remote_host")]
33+
pub local: bool,
3034
}
3135

3236
/// Run the setup command
3337
pub async fn cmd_setup(args: &SetupArgs, quiet: bool) -> Result<()> {
3438
// Load existing config (or create default)
3539
let existing_config = load_config_or_default().ok();
40+
let target_host = crate::resolve_target_host(args.remote_host.as_deref(), args.local);
3641

3742
if args.bootstrap {
38-
return run_bootstrap_setup(existing_config, args.host.as_deref(), quiet).await;
43+
return run_bootstrap_setup(existing_config, target_host.as_deref(), quiet).await;
3944
}
4045

4146
// Handle --yes flag for non-interactive mode
@@ -75,7 +80,7 @@ pub async fn cmd_setup(args: &SetupArgs, quiet: bool) -> Result<()> {
7580
println!();
7681

7782
// Check if container is already running
78-
let (client, host_name) = crate::resolve_docker_client(args.host.as_deref()).await?;
83+
let (client, host_name) = crate::resolve_docker_client(target_host.as_deref()).await?;
7984
let is_running = container_is_running(&client, CONTAINER_NAME)
8085
.await
8186
.unwrap_or(false);
@@ -117,7 +122,7 @@ pub async fn cmd_setup(args: &SetupArgs, quiet: bool) -> Result<()> {
117122
timeout: 60,
118123
remove: false,
119124
};
120-
cmd_stop(&stop_args, args.host.as_deref(), quiet).await?;
125+
cmd_stop(&stop_args, target_host.as_deref(), quiet).await?;
121126
println!();
122127
}
123128

@@ -126,14 +131,14 @@ pub async fn cmd_setup(args: &SetupArgs, quiet: bool) -> Result<()> {
126131
port: Some(new_config.opencode_web_port),
127132
..Default::default()
128133
};
129-
cmd_start(&start_args, args.host.as_deref(), quiet, 0).await?;
134+
cmd_start(&start_args, target_host.as_deref(), quiet, 0).await?;
130135

131136
Ok(())
132137
}
133138

134139
async fn run_bootstrap_setup(
135140
existing_config: Option<Config>,
136-
host: Option<&str>,
141+
target_host: Option<&str>,
137142
quiet: bool,
138143
) -> Result<()> {
139144
let new_config = build_bootstrap_config(existing_config.clone());
@@ -143,7 +148,7 @@ async fn run_bootstrap_setup(
143148
return start_or_restart_after_setup(
144149
existing_config.as_ref(),
145150
&new_config,
146-
host,
151+
target_host,
147152
quiet,
148153
true,
149154
)
@@ -161,7 +166,14 @@ async fn run_bootstrap_setup(
161166
);
162167
println!();
163168

164-
start_or_restart_after_setup(existing_config.as_ref(), &new_config, host, quiet, true).await
169+
start_or_restart_after_setup(
170+
existing_config.as_ref(),
171+
&new_config,
172+
target_host,
173+
quiet,
174+
true,
175+
)
176+
.await
165177
}
166178

167179
fn build_bootstrap_config(existing_config: Option<Config>) -> Config {
@@ -176,11 +188,11 @@ fn build_bootstrap_config(existing_config: Option<Config>) -> Config {
176188
async fn start_or_restart_after_setup(
177189
existing_config: Option<&Config>,
178190
new_config: &Config,
179-
host: Option<&str>,
191+
target_host: Option<&str>,
180192
quiet: bool,
181193
non_interactive: bool,
182194
) -> Result<()> {
183-
let (client, host_name) = crate::resolve_docker_client(host).await?;
195+
let (client, host_name) = crate::resolve_docker_client(target_host).await?;
184196
let is_running = container_is_running(&client, CONTAINER_NAME)
185197
.await
186198
.unwrap_or(false);
@@ -199,14 +211,14 @@ async fn start_or_restart_after_setup(
199211
timeout: 60,
200212
remove: false,
201213
};
202-
cmd_stop(&stop_args, host, quiet || non_interactive).await?;
214+
cmd_stop(&stop_args, target_host, quiet || non_interactive).await?;
203215
}
204216

205217
let start_args = crate::commands::StartArgs {
206218
port: Some(new_config.opencode_web_port),
207219
..Default::default()
208220
};
209-
cmd_start(&start_args, host, quiet || non_interactive, 0).await?;
221+
cmd_start(&start_args, target_host, quiet || non_interactive, 0).await?;
210222
Ok(())
211223
}
212224

packages/cli-rust/src/commands/start.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ fn show_start_result(
10941094
quiet: bool,
10951095
host_name: Option<&str>,
10961096
) {
1097-
// Get remote host address if using --host
1097+
// Get remote host address if using --remote-host
10981098
let maybe_remote_addr = resolve_remote_addr(host_name);
10991099

11001100
if quiet {

packages/cli-rust/src/commands/status.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub async fn cmd_status(
156156
.map(|cfg| cfg.bind_address.as_str())
157157
.unwrap_or("127.0.0.1");
158158

159-
// Get remote host address if using --host
159+
// Get remote host address if using --remote-host
160160
let maybe_remote_addr = resolve_remote_addr(host_name.as_deref());
161161

162162
// Normal mode: print formatted status
@@ -579,7 +579,7 @@ fn print_cockpit(
579579
)
580580
);
581581
let user_cmd = if let Some(name) = maybe_host_name {
582-
format!("occ user add <username> --host {name}")
582+
format!("occ user add <username> --remote-host {name}")
583583
} else {
584584
"occ user add <username>".to_string()
585585
};

packages/cli-rust/src/commands/user/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ pub async fn cmd_user(
5757
// Check container is running first
5858
if !container_is_running(&client, CONTAINER_NAME).await? {
5959
let msg = if let Some(name) = &host_name {
60-
format!("Container not running on {name}. Start with `occ start --host {name}`.")
60+
format!(
61+
"Container not running on {name}. Start with `occ start --remote-host {name}`."
62+
)
6163
} else {
6264
"Container not running. Start with `occ start` first.".to_string()
6365
};

packages/cli-rust/src/lib.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ struct Cli {
4040
no_color: bool,
4141

4242
/// Target remote host (overrides default_host)
43-
#[arg(long, global = true)]
44-
host: Option<String>,
43+
#[arg(long, global = true, conflicts_with = "local")]
44+
remote_host: Option<String>,
45+
46+
/// Force local Docker (ignores default_host)
47+
#[arg(long, global = true, conflicts_with = "remote_host")]
48+
local: bool,
4549
}
4650

4751
#[derive(Subcommand)]
@@ -90,26 +94,39 @@ fn get_banner() -> &'static str {
9094
"#
9195
}
9296

93-
/// Resolve which Docker client to use based on --host flag and default_host config
94-
///
95-
/// Returns (DockerClient, Option<host_name>) where host_name is Some for remote connections.
97+
/// Resolve the target host name based on flags and hosts.json
9698
///
9799
/// Resolution order:
98-
/// 1. --host flag (explicit)
99-
/// 2. default_host from hosts.json
100-
/// 3. Local Docker (no host_name)
100+
/// 1. --local (force local Docker)
101+
/// 2. --remote-host flag (explicit)
102+
/// 3. default_host from hosts.json
103+
/// 4. Local Docker (no host_name)
104+
pub fn resolve_target_host(remote_host: Option<&str>, force_local: bool) -> Option<String> {
105+
if force_local {
106+
return None;
107+
}
108+
109+
if let Some(name) = remote_host {
110+
return Some(name.to_string());
111+
}
112+
113+
let hosts = load_hosts().unwrap_or_default();
114+
hosts.default_host.clone()
115+
}
116+
117+
/// Resolve which Docker client to use based on an explicit target host name
118+
///
119+
/// Returns (DockerClient, Option<host_name>) where host_name is Some for remote connections.
101120
pub async fn resolve_docker_client(
102121
maybe_host: Option<&str>,
103122
) -> anyhow::Result<(DockerClient, Option<String>)> {
104123
let hosts = load_hosts().unwrap_or_default();
105124

106125
// Determine target host
107-
let target_host = maybe_host
108-
.map(String::from)
109-
.or_else(|| hosts.default_host.clone());
126+
let target_host = maybe_host.map(String::from);
110127

111128
match target_host {
112-
Some(name) if name != "local" && !name.is_empty() => {
129+
Some(name) => {
113130
// Remote host requested
114131
let host_config = hosts.get_host(&name).ok_or_else(|| {
115132
anyhow::anyhow!(
@@ -120,7 +137,7 @@ pub async fn resolve_docker_client(
120137
let client = DockerClient::connect_remote(host_config, &name).await?;
121138
Ok((client, Some(name)))
122139
}
123-
_ => {
140+
None => {
124141
// Local Docker
125142
let client = DockerClient::new()?;
126143
Ok((client, None))
@@ -228,8 +245,8 @@ pub fn run() -> Result<()> {
228245
eprintln!("{} Data: {}", style("[info]").cyan(), data_dir);
229246
}
230247

231-
// Store host flag for command handlers
232-
let target_host = cli.host.clone();
248+
// Store target host for command handlers
249+
let target_host = resolve_target_host(cli.remote_host.as_deref(), cli.local);
233250

234251
match cli.command {
235252
Some(Commands::Start(args)) => {

0 commit comments

Comments
 (0)