Skip to content

Commit

Permalink
add: settings.shared.alias_file
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukesor committed Aug 16, 2022
1 parent 4dcaa8e commit 63e4bda
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The concept of SemVer is applied to the daemon/client API, but not the library A

## [0.21.0] - unreleased


### Added

- Added `Settings.shared.alias_file`, which can be used to specify the location of the `pueue_aliases.yml`.

### Changed

- The process handling code has been moved from the daemon to `pueue_lib`. See [#336](https://github.com/Nukesor/pueue/issues/336).
Expand Down
4 changes: 4 additions & 0 deletions lib/src/network/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub struct StartMessage {
pub children: bool,
}

/// The messages used to restart tasks.
/// It's possible to update the command and paths when restarting tasks.
#[derive(PartialEq, Eq, Clone, Debug, Deserialize, Serialize)]
pub struct RestartMessage {
pub tasks: Vec<TasksToRestart>,
Expand All @@ -138,7 +140,9 @@ pub struct RestartMessage {
#[derive(PartialEq, Eq, Clone, Debug, Deserialize, Serialize)]
pub struct TasksToRestart {
pub task_id: usize,
/// The command that should be used when restarting the task.
pub command: String,
/// The path that should be used when restarting the task.
pub path: PathBuf,
}

Expand Down
30 changes: 27 additions & 3 deletions lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ pub struct Shared {
/// The directory that is used for all of pueue's state. \
/// I.e. task logs, state dumps, etc.
pub pueue_directory: Option<PathBuf>,
/// Don't access this property directly, but rather use the getter with the same name.
/// It's only public to allow proper integration testing.
///
/// The location where runtime related files will be placed.
/// Defaults to `pueue_directory` unless `$XDG_RUNTIME_DIR` is set.
pub runtime_directory: Option<PathBuf>,
/// Don't access this property directly, but rather use the getter with the same name.
/// It's only public to allow proper integration testing.
///
/// The location of the alias file used by the daemon/client when working with
/// aliases.
pub alias_file: Option<PathBuf>,

/// If this is set to true, unix sockets will be used.
/// Otherwise we default to TCP+TLS
#[cfg(not(target_os = "windows"))]
#[serde(default = "default_true")]
pub use_unix_socket: bool,
/// The path where the daemon's PID is located.
/// This is by default in `runtime_directory/pueue.pid`.
pub pid_path: Option<PathBuf>,
/// Don't access this property directly, but rather use the getter with the same name.
/// It's only public to allow proper integration testing.
///
Expand All @@ -43,6 +50,11 @@ pub struct Shared {
/// The TCP port.
#[serde(default = "default_port")]
pub port: String,

/// The path where the daemon's PID is located.
/// This is by default in `runtime_directory/pueue.pid`.
pub pid_path: Option<PathBuf>,

/// Don't access this property directly, but rather use the getter with the same name.
/// It's only public to allow proper integration testing.
///
Expand Down Expand Up @@ -219,6 +231,18 @@ impl Shared {
}
}

/// The location of the alias file used by the daemon/client when working with
/// task aliases.
pub fn alias_file(&self) -> PathBuf {
if let Some(path) = &self.alias_file {
expand_home(path)
} else if let Some(config_dir) = dirs::config_dir() {
config_dir.join("pueue_aliases.yml")
} else {
PathBuf::from("pueue_aliases.yml")
}
}

/// The daemon's pid path can either be explicitly specified or it's simply placed in the
/// current runtime directory.
pub fn pid_path(&self) -> PathBuf {
Expand Down
1 change: 1 addition & 0 deletions lib/tests/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn get_shared_settings(
let shared_settings = Shared {
pueue_directory: Some(tempdir_path.to_path_buf()),
runtime_directory: Some(tempdir_path.to_path_buf()),
alias_file: None,
#[cfg(not(target_os = "windows"))]
use_unix_socket,
#[cfg(not(target_os = "windows"))]
Expand Down

0 comments on commit 63e4bda

Please sign in to comment.