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

Refactor the manifest code to contain all modification #577

Closed
ruben-arts opened this issue Dec 18, 2023 · 1 comment · Fixed by #572
Closed

Refactor the manifest code to contain all modification #577

ruben-arts opened this issue Dec 18, 2023 · 1 comment · Fixed by #572
Assignees
Milestone

Comments

@ruben-arts
Copy link
Contributor

As an example this function works both on the toml table and the the actual manifest code. All toml modification should be located in the manifest code.

pub fn add_task(
        &mut self,
        name: impl AsRef<str>,
        task: Task,
        platform: Option<Platform>,
    ) -> miette::Result<()> {
        let table = if let Some(platform) = platform {
            if self
                .target_specific_tasks(platform)
                .contains_key(name.as_ref())
            {
                miette::bail!("task {} already exists", name.as_ref());
            }
            ensure_toml_target_table(&mut self.doc, platform, "tasks")?
        } else {
            self.doc["tasks"]
                .or_insert(Item::Table(Table::new()))
                .as_table_mut()
                .ok_or_else(|| {
                    miette::miette!("target table in {} is malformed", consts::PROJECT_MANIFEST)
                })?
        };
        let depends_on = task.depends_on();

        for depends in depends_on {
            if !self.manifest.tasks.contains_key(depends) {
                miette::bail!(
                    "task '{}' for the depends on for '{}' does not exist",
                    depends,
                    name.as_ref(),
                );
            }
        }

        // Add the task to the table
        table.insert(name.as_ref(), task_as_toml(task.clone()));

        self.manifest.tasks.insert(name.as_ref().to_string(), task);

        self.save()?;

        Ok(())
    }
@ruben-arts ruben-arts converted this from a draft issue Dec 18, 2023
@ruben-arts ruben-arts self-assigned this Dec 18, 2023
@ruben-arts
Copy link
Contributor Author

Closed with #572

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant