Repository: Canop/bacon (language: rust)

Issue:
Default `bacon.toml` overrides `prefs.toml` configured jobs
I have some default jobs to use on projects that haven't configured `bacon` themselves in my `prefs.toml`. To use them I still need to `touch bacon.toml` in each project to stop the default package config overriding my system configuration. It feels like these defaults should not override anything that has been explicitly configured in `prefs.toml`.


Discussion / hints:


Right now I don't really see how to handle your concern in a convenient and obvious way but it's noted, thanks.
It would be awesome if this behavior was mentioned on the config page. I tried to add some env vars to the default run job and i was really confused why they weren't applying. I ended up creating a new job and binding that to r instead.
**TL;DR** - My suggestion for a convenient and obvious way to solve this concern would be to add one more file `~/.config/bacon/config.toml` that overrides all other files (including project-specific configuration). This would allow a user to override settings and configure bacon personally without making changes in version-controlled project files.

---

I just ran into this and it is extremely confusing. I see that my `prefs.toml` is being loaded (seeing as the custom jobs existed) but I couldn't understand why the `default_job` wasn't being respected. This was "solved" by running `touch bacon.toml` as mentioned by @Nemo157 - however this is not a great solution because it is a version controlled file which is not always possible to modify.

The [website mentions](https://dystroy.org/bacon/config/):
> All accept the same properties (preferences, keybindings, jobs, etc.). The properties of the global prefs.toml file are overriden by the workspace level bacon.toml file, then by the package level bacon.toml file.

One would assume that _without creating_ a `bacon.toml` file, the `prefs.toml` file would actually be useful for "the same properties". However now I understand there is an _implicit_ `bacon.toml` file overriding my `prefs.toml` file that makes the `prefs.toml` almost useless. Confusion could be averted if the implicit default `bacon.toml` file did not define anything (or was not implicit) -- and those jobs and preferences would be defined in the default `prefs.toml` instead.

The fact that the highest-priority configuration is in a version controlled file within the project directory means that in order to make bacon's configuration useful for me I must commit an empty `bacon.toml` file into every project, and it isn't useful at all in projects where I cannot commit such a file.

Fix patch:
diff --git a/bacon.toml b/bacon.toml
index 7662e34..71d3493 100644
--- a/bacon.toml
+++ b/bacon.toml
@@ -67,6 +67,7 @@ command = [
 	"-A", "clippy::len_without_is_empty",
 	"-A", "clippy::get_first",
 	"-A", "clippy::while_let_on_iterator",
+	"-A", "clippy::if_same_then_else",
 ]
 need_stdout = false
 
diff --git a/src/auto_refresh.rs b/src/auto_refresh.rs
index d7ba7fe..c19c7b9 100644
--- a/src/auto_refresh.rs
+++ b/src/auto_refresh.rs
@@ -1,7 +1,11 @@
 #[derive(Debug, Clone, Copy, PartialEq)]
 pub enum AutoRefresh {
+    /// Don't rerun the job on file changes.
     Paused,
+    /// Don't rerun the job, also we already missed some changes
+    /// (so if we enable, we should immediately rerun the job).
     PausedWithMisses,
+    /// Run the job on file changes.
     Enabled,
 }
 
diff --git a/src/cli.rs b/src/cli.rs
index 3eea52f..02c3a9d 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -50,6 +50,9 @@ pub fn run() -> anyhow::Result<()> {
 
     let mut settings = Settings::default();
 
+    let default_package_config = Config::default_package_config();
+    settings.apply_config(&default_package_config);
+
     if let Some(project_dir) = ProjectDirs::from("org", "dystroy", "bacon") {
         let prefs_path = project_dir.config_dir().join("prefs.toml");
         if args.prefs {
@@ -94,12 +97,10 @@ pub fn run() -> anyhow::Result<()> {
         println!("{}", package_config_path.to_string_lossy());
         return Ok(());
     }
-    let package_config = if package_config_path.exists() {
-        Config::from_path(&package_config_path)?
-    } else {
-        Config::default_package_config()
-    };
-    settings.apply_config(&package_config);
+    if package_config_path.exists() {
+        let config = Config::from_path(&package_config_path)?;
+        settings.apply_config(&config);
+    }
 
     // args are applied after prefs, and package config so that they can override them
     settings.apply_args(&args);
diff --git a/src/examples.rs b/src/examples.rs
index 6958a1c..8281a25 100644
--- a/src/examples.rs
+++ b/src/examples.rs
@@ -12,6 +12,7 @@ ${examples
 }
 ";
 
+/// Examples to display in the --help message
 pub static EXAMPLES: &[Example] = &[
     Example {
         title: "Start with the default job",
diff --git a/src/executor.rs b/src/executor.rs
index 174b464..04f99ca 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -33,6 +33,8 @@ pub struct MissionExecutor {
     pub line_receiver: Receiver<CommandExecInfo>,
 }
 
+/// Dedicated to one execution of the job (so there's usually
+/// several task executors during the lifetime of a mission executor)
 pub struct TaskExecutor {
     /// the thread running the current task
     child_thread: thread::JoinHandle<()>,
@@ -46,6 +48,7 @@ enum StopMessage {
     Kill,       // kill the process, don't bother about the status
 }
 
+/// Settings for one execution of job's command
 #[derive(Debug, Clone, Copy, PartialEq, Default)]
 pub struct Task {
     pub backtrace: bool,
@@ -89,6 +92,7 @@ impl MissionExecutor {
         })
     }
 
+    /// Start the job's command, once, with the given settings
     pub fn start(
         &mut self,
         task: Task,
diff --git a/src/state.rs b/src/state.rs
index 961b45c..793333a 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -22,8 +22,8 @@ use {
     },
 };
 
-/// contains the currently rendered state of the application,
-/// including scroll position and the current report (if any)
+/// Currently rendered state of the application, including scroll position
+/// and the current report (if any)
 pub struct AppState<'s> {
     /// the mission to run, with settings
     pub mission: Mission<'s>,


Test patch: