Skip to content

Update config directory resolution#42

Open
tomassliz wants to merge 4 commits intopointfreeco:mainfrom
tomassliz:config-directory
Open

Update config directory resolution#42
tomassliz wants to merge 4 commits intopointfreeco:mainfrom
tomassliz:config-directory

Conversation

@tomassliz
Copy link

@tomassliz tomassliz commented Feb 18, 2026

The motivation behind this is to enable the ability to set a custom path for the configuration directory. The configuration path is generated when the pfw login command is invoked, so the environment variable should already be present. I’ve tried to keep this simple and omitted adding an option for existing commands or the new command altogether.

The order in which the configuration directory is resolved is as follows:

PFW_HOMEXDG_CONFIG_HOME/pfw~/.pfw

Fixes #36.

Copy link
Member

@stephencelis stephencelis left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this! We are definitely down to merge but could you please address the following?

Comment on lines +5 to +44
var machineURL: URL {
pfwDirectoryURL.appendingPathComponent("machine")
}

var tokenURL: URL {
pfwDirectoryURL.appendingPathComponent("token")
}

var shaURL: URL {
pfwDirectoryURL.appendingPathComponent("sha")
}

var pfwDirectoryURL: URL {
pfwDirectoryEnvOverride ?? xdgDirectoryURL ?? defaultPfwDirectoryURL
}

private var defaultPfwDirectoryURL: URL {
@Dependency(\.fileSystem) var fileSystem
return fileSystem.homeDirectoryForCurrentUser
.appendingPathComponent(".pfw", isDirectory: true)
}

private var pfwDirectoryEnvOverride: URL? {
let pfwHome = ProcessInfo.processInfo.environment["PFW_HOME"]
if let path = pfwHome?.trimmingCharacters(in: .whitespacesAndNewlines), !path.isEmpty {
return URL(fileURLWithPath: path, isDirectory: true)
} else {
return nil
}
}

private var xdgDirectoryURL: URL? {
let xdgConfigDir = ProcessInfo.processInfo.environment["XDG_CONFIG_HOME"]
if let path = xdgConfigDir?.trimmingCharacters(in: .whitespacesAndNewlines), !path.isEmpty {
return URL(fileURLWithPath: path, isDirectory: true)
.appendingPathComponent("pfw", isDirectory: true)
} else {
return nil
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you refactor this back to look like mostly the original? These aren't reused helpers and inlining things again should be significantly shorter and easier to see what the difference is.

}

private var xdgDirectoryURL: URL? {
let xdgConfigDir = ProcessInfo.processInfo.environment["XDG_CONFIG_HOME"]
Copy link
Member

Choose a reason for hiding this comment

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

Rather than use ProcessInfo.processInfo.environment directly, and then use getenv and setenv for tests, can you control this dependency? There are a few examples in the Dependencies directory.

@stephencelis
Copy link
Member

@tomassliz Just checking in. Are you interested in addressing the above feedback to get this merged?

@tomassliz
Copy link
Author

@stephencelis I’ll address these by the end of this week. I apologize for the delay.

@tomassliz
Copy link
Author

@stephencelis, I’ve just pushed changes that address your feedback. Please review them. I believe you should be the one to close the remaining comments.

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.

Option for setting default config path

2 participants