Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish between StatesSaved and StatesCurrent #60

Merged
merged 12 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
docs_and_spell_check:
name: Docs and Spell Check
runs-on: ubuntu-latest
timeout-minutes: 3
timeout-minutes: 10
env:
RUSTDOCFLAGS: "-Dwarnings"
steps:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
* `ShCmdItemSpec` takes in optional `ShCmdParams<Id>` and inserts it into `resources`. ([#57])
* `CmdContextBuilder` sets the current directory to the workspace directory. ([#57])
* `StatesDesired` is now stored as `State<Logical, Placeholder>`. ([#52], [#58])
* Re-read discovered `States` are now named `StatesSaved`. ([#52], [#60])
* `StatesCurrent` is only present when the discovered in the current execution. ([#52], [#60])
* `States*Deserialize` errors are consolidated into a single variant. ([#52], [#60])
* `States*Serialize` errors are consolidated into a single variant. ([#52], [#60])

[#57]: https://github.com/azriel91/peace/pull/57
[#52]: https://github.com/azriel91/peace/issues/52
[#58]: https://github.com/azriel91/peace/pull/58
[#60]: https://github.com/azriel91/peace/pull/60


## 0.0.4 (2022-11-29)
Expand Down
21 changes: 18 additions & 3 deletions crate/cfg/src/state/placeholder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
use std::fmt;
use std::{fmt, marker::PhantomData};

use serde::{Deserialize, Serialize};

/// Placeholder for physical state to be computed.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Placeholder;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub enum Placeholder {
/// Placeholder indicating this value is calculated.
///
/// Using a newtype enum has the benefit of having a `!Calculated` tag in
/// the serialized YAML form.
Calculated(PhantomData<()>),
}

impl Placeholder {
/// Returns the `Calculated` variant.
///
/// Convenience function so consumers don't have to import `PhantomData`.
pub fn calculated() -> Self {
Self::Calculated(PhantomData)
}
}

impl fmt::Display for Placeholder {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
4 changes: 2 additions & 2 deletions crate/core/src/flow_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use serde::{Deserialize, Serialize};
///
/// ```bash
/// peace dev_env discover # StatesDiscoverCmd
/// peace dev_env status # StatesCurrentDisplayCmd
/// peace dev_env status # StatesSavedDisplayCmd
/// peace dev_env deploy # EnsureCmd
/// peace dev_env clean # CleanCmd
///
/// peace artifact discover # StatesDiscoverCmd
/// peace artifact status # StatesCurrentDisplayCmd
/// peace artifact status # StatesSavedDisplayCmd
/// peace artifact publish # EnsureCmd
/// ```
///
Expand Down
6 changes: 3 additions & 3 deletions crate/resources/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@

pub use self::{
flow_dir::FlowDir, peace_dir::PeaceDir, profile_dir::ProfileDir,
profile_history_dir::ProfileHistoryDir, states_current_file::StatesCurrentFile,
states_desired_file::StatesDesiredFile, workspace_dir::WorkspaceDir,
profile_history_dir::ProfileHistoryDir, states_desired_file::StatesDesiredFile,
states_saved_file::StatesSavedFile, workspace_dir::WorkspaceDir,
};

mod flow_dir;
mod peace_dir;
mod profile_dir;
mod profile_history_dir;
mod states_current_file;
mod states_desired_file;
mod states_saved_file;
mod workspace_dir;

/// Common impl logic for `PathBuf` newtypes.
Expand Down
28 changes: 0 additions & 28 deletions crate/resources/src/paths/states_current_file.rs

This file was deleted.

28 changes: 28 additions & 0 deletions crate/resources/src/paths/states_saved_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::path::PathBuf;

use crate::paths::FlowDir;

/// Path to the file that stores item specs' states.
///
/// Typically `$workspace_dir/.peace/$profile/$flow_id/states_saved.yaml`.
///
/// See `StatesSavedFile::from<&FlowDir>` if you want to construct a
/// `StatesSavedFile` with the conventional `$flow_dir/states_saved.yaml`
/// path.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StatesSavedFile(PathBuf);

crate::paths::pathbuf_newtype!(StatesSavedFile);

impl StatesSavedFile {
/// File name of the states file.
pub const NAME: &'static str = "states_saved.yaml";
}

impl From<&FlowDir> for StatesSavedFile {
fn from(flow_dir: &FlowDir) -> Self {
let path = flow_dir.join(Self::NAME);

Self(path)
}
}
84 changes: 69 additions & 15 deletions crate/resources/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use std::{

use crate::{
resources::ts::{
Cleaned, CleanedDry, Empty, Ensured, EnsuredDry, SetUp, WithStateDiffs, WithStates,
WithStatesCurrentAndDesired, WithStatesDesired,
Cleaned, CleanedDry, Empty, Ensured, EnsuredDry, SetUp, WithStatesCurrent,
WithStatesCurrentAndDesired, WithStatesCurrentDiffs, WithStatesDesired, WithStatesSaved,
WithStatesSavedAndDesired, WithStatesSavedDiffs,
},
states::{
StateDiffs, StatesCleaned, StatesCleanedDry, StatesCurrent, StatesDesired, StatesEnsured,
StatesEnsuredDry,
StatesEnsuredDry, StatesSaved,
},
};

Expand Down Expand Up @@ -84,8 +85,20 @@ impl From<Resources<Empty>> for Resources<SetUp> {
}
}

// For `StatesSavedReadCmd` after `StatesSaved` have been read.
impl From<(Resources<SetUp>, StatesSaved)> for Resources<WithStatesSaved> {
fn from((mut resources, states): (Resources<SetUp>, StatesSaved)) -> Self {
resources.insert(states);

Self {
inner: resources.into_inner(),
marker: PhantomData,
}
}
}

// For `StatesCurrentDiscoverCmd` after `StatesCurrent` have been discovered.
impl From<(Resources<SetUp>, StatesCurrent)> for Resources<WithStates> {
impl From<(Resources<SetUp>, StatesCurrent)> for Resources<WithStatesCurrent> {
fn from((mut resources, states): (Resources<SetUp>, StatesCurrent)) -> Self {
resources.insert(states);

Expand All @@ -108,13 +121,35 @@ impl From<(Resources<SetUp>, StatesDesired)> for Resources<WithStatesDesired> {
}
}

impl From<(Resources<SetUp>, StatesSaved, StatesDesired)> for Resources<WithStatesSavedAndDesired> {
fn from(
(mut resources, states_saved, states_desired): (
Resources<SetUp>,
StatesSaved,
StatesDesired,
),
) -> Self {
resources.insert(states_saved);
resources.insert(states_desired);

Self {
inner: resources.into_inner(),
marker: PhantomData,
}
}
}

impl From<(Resources<SetUp>, StatesCurrent, StatesDesired)>
for Resources<WithStatesCurrentAndDesired>
{
fn from(
(mut resources, states, states_desired): (Resources<SetUp>, StatesCurrent, StatesDesired),
(mut resources, states_current, states_desired): (
Resources<SetUp>,
StatesCurrent,
StatesDesired,
),
) -> Self {
resources.insert(states);
resources.insert(states_current);
resources.insert(states_desired);

Self {
Expand All @@ -124,7 +159,22 @@ impl From<(Resources<SetUp>, StatesCurrent, StatesDesired)>
}
}

impl From<(Resources<WithStatesCurrentAndDesired>, StateDiffs)> for Resources<WithStateDiffs> {
impl From<(Resources<WithStatesSavedAndDesired>, StateDiffs)> for Resources<WithStatesSavedDiffs> {
fn from(
(mut resources, state_diffs): (Resources<WithStatesSavedAndDesired>, StateDiffs),
) -> Self {
resources.insert(state_diffs);

Self {
inner: resources.into_inner(),
marker: PhantomData,
}
}
}

impl From<(Resources<WithStatesCurrentAndDesired>, StateDiffs)>
for Resources<WithStatesCurrentDiffs>
{
fn from(
(mut resources, state_diffs): (Resources<WithStatesCurrentAndDesired>, StateDiffs),
) -> Self {
Expand All @@ -137,9 +187,9 @@ impl From<(Resources<WithStatesCurrentAndDesired>, StateDiffs)> for Resources<Wi
}
}

impl From<(Resources<WithStateDiffs>, StatesEnsuredDry)> for Resources<EnsuredDry> {
impl From<(Resources<WithStatesCurrentDiffs>, StatesEnsuredDry)> for Resources<EnsuredDry> {
fn from(
(mut resources, states_ensured_dry): (Resources<WithStateDiffs>, StatesEnsuredDry),
(mut resources, states_ensured_dry): (Resources<WithStatesCurrentDiffs>, StatesEnsuredDry),
) -> Self {
resources.insert(states_ensured_dry);

Expand All @@ -150,8 +200,10 @@ impl From<(Resources<WithStateDiffs>, StatesEnsuredDry)> for Resources<EnsuredDr
}
}

impl From<(Resources<WithStateDiffs>, StatesEnsured)> for Resources<Ensured> {
fn from((mut resources, states_ensured): (Resources<WithStateDiffs>, StatesEnsured)) -> Self {
impl From<(Resources<WithStatesCurrentDiffs>, StatesEnsured)> for Resources<Ensured> {
fn from(
(mut resources, states_ensured): (Resources<WithStatesCurrentDiffs>, StatesEnsured),
) -> Self {
resources.insert(states_ensured);

Self {
Expand All @@ -161,9 +213,9 @@ impl From<(Resources<WithStateDiffs>, StatesEnsured)> for Resources<Ensured> {
}
}

impl From<(Resources<WithStates>, StatesCleanedDry)> for Resources<CleanedDry> {
impl From<(Resources<WithStatesCurrent>, StatesCleanedDry)> for Resources<CleanedDry> {
fn from(
(mut resources, states_cleaned_dry): (Resources<WithStates>, StatesCleanedDry),
(mut resources, states_cleaned_dry): (Resources<WithStatesCurrent>, StatesCleanedDry),
) -> Self {
resources.insert(states_cleaned_dry);

Expand All @@ -174,8 +226,10 @@ impl From<(Resources<WithStates>, StatesCleanedDry)> for Resources<CleanedDry> {
}
}

impl From<(Resources<WithStates>, StatesCleaned)> for Resources<Cleaned> {
fn from((mut resources, states_cleaned): (Resources<WithStates>, StatesCleaned)) -> Self {
impl From<(Resources<WithStatesCurrent>, StatesCleaned)> for Resources<Cleaned> {
fn from(
(mut resources, states_cleaned): (Resources<WithStatesCurrent>, StatesCleaned),
) -> Self {
resources.insert(states_cleaned);

Self {
Expand Down
Loading