Skip to content

Commit

Permalink
--config-toml argument (#296)
Browse files Browse the repository at this point in the history
Fix #284
  • Loading branch information
Canop authored Jan 15, 2025
1 parent 11c7ea6 commit a62148a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/conf/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ pub struct Args {
#[clap(long, value_name = "project")]
pub project: Option<String>,

/// Configuration passed as a TOML string
#[clap(long)]
pub config_toml: Option<String>,

#[clap()]
/// What to do: either a job, or a path, or both
pub args: Vec<String>,
Expand Down
7 changes: 7 additions & 0 deletions src/conf/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl Settings {
/// * the package level `bacon.toml` file in package-root/.bacon.toml
/// * the package level `bacon.toml` file in package-root/.config/.bacon.toml
/// * the file whose path is in environment variable `BACON_CONFIG`
/// * the content of the `--config-toml` argument
/// * args given as arguments, coming from the cli call
pub fn read(
args: &Args,
Expand Down Expand Up @@ -122,6 +123,12 @@ impl Settings {
}
}

if let Some(toml) = &args.config_toml {
let config = toml::from_str(toml)?;
info!("config loaded from --config-toml: {:#?}", &config);
settings.apply_config(&config);
}

settings.apply_args(args);
settings.check()?;
info!("settings: {:#?}", &settings);
Expand Down
2 changes: 2 additions & 0 deletions website/docs/community/bacon-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ If bacon didn't understand correctly the output of a cargo tool, it may also be

If you think you might help, as a tester or coder, you're welcome, but please read [Contributing to my FOSS projects](https://dystroy.org/blog/contributing/) before starting a PR.


**Don't open a PR without discussing the design before**, either in the chat or in an issue, unless you're just fixing a typo. Coding is the easy part. Determining the exact requirement and how we want it to be done is the hard part. This is especially important if you plan to add a dependency or to change the visible parts, eg the launch arguments.
1 change: 1 addition & 0 deletions website/docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Bacon loads in order:
* the `bacon.toml` file in `package-root/`
* the `bacon.toml` file in `package-root/.config/`
* the file whose path is in environment variable `BACON_CONFIG`
* the content of the `--config-toml` argument

Each configuration file overrides the properties of previously loaded ones.

Expand Down
23 changes: 23 additions & 0 deletions website/docs/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,28 @@ You would call it with
bacon ex -- example4578
```

# Bacon CLI snippets

You may share a command-line snippet without requiring a bacon.toml file, using the `--config-toml` argument:

```bash
bacon -j cli-test --config-toml '
[jobs.cli-test]
command = [
"sh",
"-c",
"echo \"hello $(date +%H-%M-%S)\"; cargo run",
]
need_stdout = true
allow_warnings = true
background = false
on_change_strategy = "kill_then_restart"
kill = ["pkill", "-TERM", "-P"]'
```

Notes:

* wrap the inline configuration item in single quotes so that you may use double-quotes inside
* this configuration is simply added to the other ones and it may refer to them
* if you add a job this way and want it executed, either define it as `default_job` in the same inline TOML or use the `--job`/`-j` argument as in the example above

0 comments on commit a62148a

Please sign in to comment.