Skip to content

Add default directory to payjoin-cli#874

Merged
nothingmuch merged 1 commit into
payjoin:masterfrom
zealsham:add-default-directory
Aug 5, 2025
Merged

Add default directory to payjoin-cli#874
nothingmuch merged 1 commit into
payjoin:masterfrom
zealsham:add-default-directory

Conversation

@zealsham

@zealsham zealsham commented Jul 14, 2025

Copy link
Copy Markdown
Collaborator

SUMMARY

This PR enables payjoin-cli to automatically discover config files in standard locations following XDG Base Directory specification or use the current working directory . config values in the current working directory takes precedent over that of the xdg-compliant vlaue . If a required config value is missing in the current directory config , Payjoin-cli falls back to using values from the xdg-compliant directory config .
This pr closes #64

Changes

  • Add config file search in XDG-compliant directories (~/.config/payjoin/)
  • Current working directory takes precedent over xdg directory
  • if a config value is missing in current working directory , fall back and use the config value in xdg-compliant directory

@coveralls

coveralls commented Jul 14, 2025

Copy link
Copy Markdown
Collaborator

Pull Request Test Coverage Report for Build 16737406990

Details

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.007%) to 85.853%

Totals Coverage Status
Change from base Build 16728605627: 0.007%
Covered Lines: 7446
Relevant Lines: 8673

💛 - Coveralls

Comment thread payjoin-cli/Cargo.toml Outdated
Comment thread payjoin-cli/src/app/config.rs Outdated
Comment thread payjoin-cli/src/main.rs Outdated
Comment thread payjoin-cli/src/main.rs Outdated
Comment thread payjoin-cli/src/main.rs Outdated
@zealsham
zealsham force-pushed the add-default-directory branch from 7e74c05 to c474b15 Compare July 20, 2025 13:48
Comment thread payjoin-cli/src/main.rs Outdated
Comment thread payjoin-cli/src/main.rs Outdated
Comment thread payjoin-cli/src/main.rs Outdated

@nothingmuch nothingmuch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ensure_config_dirs can be split into a separate commit that can be saved for a follow-up PR addressing #896

Apart from my suggestion to hold off creating the directory entirely for this PR, I think this is ready, please squash the later commits to the first one, and update the message so it's up to date (please also update the short message to be a bit clearer, maybe "payjoin-cli: search for config.toml in standard locations" or something like that, not sure that fits in 50 char suggested limit)

Comment thread payjoin-cli/src/main.rs Outdated
Comment thread payjoin-cli/src/main.rs Outdated
@zealsham
zealsham force-pushed the add-default-directory branch 2 times, most recently from 9ede585 to 06f1a27 Compare July 27, 2025 23:33

@nothingmuch nothingmuch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for addressing all review comments

i missed a potential simplification that i think is worth doing, sorry for yet another round of feedback i should have thought of this earlier

Comment thread payjoin-cli/src/main.rs Outdated
Comment thread payjoin-cli/src/main.rs Outdated
Comment thread payjoin-cli/src/main.rs Outdated
Comment thread payjoin-cli/src/app/config.rs Outdated
Comment on lines +132 to +135
let file_source = config_path
.map(|path| File::from(path).format(FileFormat::Toml).required(true))
.unwrap_or_else(|| File::new("config.toml", FileFormat::Toml).required(false));
config = config.add_source(file_source);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i missed this before but this is a bit confusing...

if find_config_path returns Some(./config.toml), then this is redundant, and if it returns Some(~/.config/payjoin-cli/config.toml) this is ignored, so this could be simplified:

Suggested change
let file_source = config_path
.map(|path| File::from(path).format(FileFormat::Toml).required(true))
.unwrap_or_else(|| File::new("config.toml", FileFormat::Toml).required(false));
config = config.add_source(file_source);
let Some(path) = config_path {
config = config.add_source(File::from(path).format(FileFormat::Toml).required(true));
}

but thinking about it more, since the config crate provides cascading support, maybe the right behavior would be to add both? ~/.config/payjoin-cli/config.toml can set global defaults, and ./config.toml can override. both can be .required(false)? i think that would simplify this PR even more, avoiding the need to check if files exist altogether since the config crate can handle that for us

@DanGould thoughts on using config this way? is there any good reason why if ./config.toml exists ~/.config/payjoin-cli/config.toml should be ignored entirely like i previously suggested? afaik the e2e test will be unaffected since it passes explicit args for everything, and that will take precedence, and for manual testing it seems more convenient to have global defaults and local overrides. we can also add --ignore-global-config, --ignore-local-config bools (and --ignore-config-files?) to the CLI options, that have the effect of skipping the config file addition

sorry for only realizing this now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of cascading defaults. and the simplicity it provides.

it seems more convenient to have global defaults and local override

I agree.

we can also add --ignore-global-config, --ignore-local-config bools (and --ignore-config-files?) to the CLI options, that have the effect of skipping the config file addition

yes we can, though I'd like to see that held off on for the future and not block this PR (just clarifying, i know you're not suggesting this)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of cascading defaults. and the simplicity it provides.

cool. so yeah @zealsham i think this means we can completely remove all the exists check, just unconditionally add both paths as sources and mark required(false)

yes we can, though I'd like to see that held off on for the future and not block this PR (just clarifying, i know you're not suggesting this)

yeah if we ever need that kind of thing for testing it's simple to add, but for now we have everything we need since CLI args are provided for all values anyway

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nothingmuch , implemented , i'll take on config flag pr after this and defaul config goes in if we are moving in that direction .

@zealsham
zealsham force-pushed the add-default-directory branch from a52f462 to c37b6d1 Compare August 4, 2025 23:35
enable payjoin-cli to search for config files in XDG-compliant
directories and current working directory. Current directory
take precedence over xdg directory for config values  .
if a required config value is missing in the current directory config
the cli will fall back to using xdg directory config value .
@zealsham
zealsham force-pushed the add-default-directory branch from c37b6d1 to 27a9cd9 Compare August 5, 2025 00:31
@nothingmuch
nothingmuch merged commit 6a8bf65 into payjoin:master Aug 5, 2025
10 checks passed
@nothingmuch

Copy link
Copy Markdown
Contributor

thanks for sticking with this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Persist data in default directory

5 participants