Skip to content

Commit 862b95d

Browse files
committed
refactor: [#220] remove unused with_working_dir functions
- Removed EnvironmentContext::with_working_dir() - not used anywhere - Removed Environment::with_working_dir() - not used anywhere - Kept EnvironmentContext::with_working_dir_and_tracker() - actively used by create command - Kept InternalConfig::with_working_dir() - used by with_working_dir_and_tracker() - Updated documentation to remove references to removed functions - All 1395+ tests pass
1 parent e22e601 commit 862b95d

File tree

2 files changed

+4
-139
lines changed

2 files changed

+4
-139
lines changed

src/domain/environment/context.rs

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -183,70 +183,10 @@ impl EnvironmentContext {
183183
}
184184
}
185185

186-
/// Creates a new environment context with directories relative to a working directory
187-
///
188-
/// This version creates absolute paths for data and build directories by
189-
/// using the provided working directory as the base.
190-
///
191-
/// # Arguments
192-
///
193-
/// * `name` - The environment name
194-
/// * `provider_config` - Provider-specific configuration (LXD, Hetzner, etc.)
195-
/// * `ssh_credentials` - SSH credentials for accessing the instance
196-
/// * `ssh_port` - SSH port (typically 22)
197-
/// * `working_dir` - The base working directory for operations
198-
///
199-
/// # Examples
200-
///
201-
/// ```rust
202-
/// use torrust_tracker_deployer_lib::domain::environment::{EnvironmentContext, EnvironmentName};
203-
/// use torrust_tracker_deployer_lib::domain::provider::{ProviderConfig, LxdConfig};
204-
/// use torrust_tracker_deployer_lib::domain::ProfileName;
205-
/// use torrust_tracker_deployer_lib::adapters::SshCredentials;
206-
/// use torrust_tracker_deployer_lib::shared::Username;
207-
/// use std::path::PathBuf;
208-
///
209-
/// let env_name = EnvironmentName::new("production".to_string())?;
210-
/// let username = Username::new("torrust".to_string())?;
211-
/// let ssh_credentials = SshCredentials::new(
212-
/// PathBuf::from("keys/prod_rsa"),
213-
/// PathBuf::from("keys/prod_rsa.pub"),
214-
/// username,
215-
/// );
216-
/// let provider_config = ProviderConfig::Lxd(LxdConfig {
217-
/// profile_name: ProfileName::new("torrust-profile-production".to_string())?,
218-
/// });
219-
/// let working_dir = PathBuf::from("/opt/deployments");
220-
///
221-
/// let context = EnvironmentContext::with_working_dir(&env_name, provider_config, ssh_credentials, 22, &working_dir);
222-
///
223-
/// assert_eq!(context.user_inputs.instance_name.as_str(), "torrust-tracker-vm-production");
224-
/// assert_eq!(context.internal_config.data_dir, PathBuf::from("/opt/deployments/data/production"));
225-
/// assert_eq!(context.internal_config.build_dir, PathBuf::from("/opt/deployments/build/production"));
226-
///
227-
/// # Ok::<(), Box<dyn std::error::Error>>(())
228-
/// ```
229-
#[must_use]
230-
pub fn with_working_dir(
231-
name: &EnvironmentName,
232-
provider_config: ProviderConfig,
233-
ssh_credentials: SshCredentials,
234-
ssh_port: u16,
235-
working_dir: &std::path::Path,
236-
) -> Self {
237-
Self {
238-
user_inputs: UserInputs::new(name, provider_config, ssh_credentials, ssh_port),
239-
internal_config: InternalConfig::with_working_dir(name, working_dir),
240-
runtime_outputs: RuntimeOutputs {
241-
instance_ip: None,
242-
provision_method: None,
243-
},
244-
}
245-
}
246-
247186
/// Creates a new environment context with custom tracker configuration
248187
///
249-
/// This is similar to `with_working_dir` but allows specifying a custom
188+
/// This creates absolute paths for data and build directories by using the
189+
/// provided working directory as the base, and allows specifying a custom
250190
/// tracker configuration instead of using the default.
251191
#[must_use]
252192
pub fn with_working_dir_and_tracker(

src/domain/environment/mod.rs

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -278,85 +278,10 @@ impl Environment {
278278
}
279279
}
280280

281-
/// Creates a new environment in Created state with directories relative to a working directory
282-
///
283-
/// This version creates absolute paths for data and build directories by
284-
/// using the provided working directory as the base. This is the recommended
285-
/// constructor when the working directory is known at environment creation time.
286-
///
287-
/// # Arguments
288-
///
289-
/// * `name` - The unique environment name
290-
/// * `provider_config` - Provider-specific configuration (LXD, Hetzner, etc.)
291-
/// * `ssh_credentials` - SSH credentials for accessing the provisioned instance
292-
/// * `ssh_port` - SSH port for connections (typically 22)
293-
/// * `working_dir` - The base working directory for all operations
294-
///
295-
/// # Returns
296-
///
297-
/// A new environment in the `Created` state with paths relative to the working directory.
298-
///
299-
/// # Examples
300-
///
301-
/// ```rust
302-
/// use torrust_tracker_deployer_lib::domain::environment::{Environment, EnvironmentName};
303-
/// use torrust_tracker_deployer_lib::domain::provider::{ProviderConfig, LxdConfig};
304-
/// use torrust_tracker_deployer_lib::domain::ProfileName;
305-
/// use torrust_tracker_deployer_lib::adapters::SshCredentials;
306-
/// use torrust_tracker_deployer_lib::shared::Username;
307-
/// use std::path::PathBuf;
308-
///
309-
/// let env_name = EnvironmentName::new("production".to_string())?;
310-
/// let username = Username::new("torrust".to_string())?;
311-
/// let ssh_credentials = SshCredentials::new(
312-
/// PathBuf::from("keys/prod_rsa"),
313-
/// PathBuf::from("keys/prod_rsa.pub"),
314-
/// username,
315-
/// );
316-
/// let provider_config = ProviderConfig::Lxd(LxdConfig {
317-
/// profile_name: ProfileName::new("torrust-profile-production".to_string())?,
318-
/// });
319-
/// let ssh_port = 22;
320-
/// let working_dir = PathBuf::from("/opt/deployments");
321-
/// let environment = Environment::with_working_dir(env_name, provider_config, ssh_credentials, ssh_port, &working_dir);
322-
///
323-
/// assert_eq!(environment.instance_name().as_str(), "torrust-tracker-vm-production");
324-
/// assert_eq!(*environment.data_dir(), PathBuf::from("/opt/deployments/data/production"));
325-
/// assert_eq!(*environment.build_dir(), PathBuf::from("/opt/deployments/build/production"));
326-
///
327-
/// # Ok::<(), Box<dyn std::error::Error>>(())
328-
/// ```
329-
///
330-
/// # Panics
331-
///
332-
/// This function does not panic. All instance name generation is guaranteed
333-
/// to succeed for valid environment names.
334-
#[must_use]
335-
#[allow(clippy::needless_pass_by_value)] // Public API takes ownership for ergonomics
336-
pub fn with_working_dir(
337-
name: EnvironmentName,
338-
provider_config: ProviderConfig,
339-
ssh_credentials: SshCredentials,
340-
ssh_port: u16,
341-
working_dir: &std::path::Path,
342-
) -> Environment<Created> {
343-
let context = EnvironmentContext::with_working_dir(
344-
&name,
345-
provider_config,
346-
ssh_credentials,
347-
ssh_port,
348-
working_dir,
349-
);
350-
351-
Environment {
352-
context,
353-
state: Created,
354-
}
355-
}
356-
357281
/// Creates a new environment in Created state with custom tracker configuration
358282
///
359-
/// This is similar to `with_working_dir` but allows specifying a custom
283+
/// This creates absolute paths for data and build directories by using the
284+
/// provided working directory as the base, and allows specifying a custom
360285
/// tracker configuration instead of using the default.
361286
#[must_use]
362287
#[allow(clippy::needless_pass_by_value)] // Public API takes ownership for ergonomics

0 commit comments

Comments
 (0)