feat: Add support for reading command-line options from dotfiles (#191)#580
Open
adminlip wants to merge 1 commit into
Open
feat: Add support for reading command-line options from dotfiles (#191)#580adminlip wants to merge 1 commit into
adminlip wants to merge 1 commit into
Conversation
…#191) Implement FileOptions service that reads .<command> dotfiles from cwd, parent directories, and user home directory. Files closer to cwd take precedence; CLI args always override file defaults. - Add FileOptions trait with Live (JVM/Native) and Noop (JS) impls - Add FileOptionsPlatformSpecific for platform-specific defaults - Update CliApp with runWithFileArgs/runWithoutFileArgs methods - Thread fromFiles parameter through Command.parse hierarchy - Add mergeFileOptions/mergeFileAndInputOptions to Options.validate - Add comprehensive tests for priority/override semantics
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #191: CLI applications can now read default option values from
.<command>dotfiles in the current working directory, its parent directories, and the user home directory.Design
FileOptionsservice trait withLive(JVM/Native) andNoop(JS/tests) implementationsOrElseroot guard: when the top-level command is(a | b), file-options lookup is silently skipped (no unique name to anchor on)FileOptionsPlatformSpecificprovidesdefault = Liveon JVM/Native,default = Noopon Scala.jsChanges
New files
FileOptions.scala— service trait +Live/NoopimplementationsFileOptionsPlatformSpecific.scala(js/jvm/native) — platform-specificdefaultvalueFileOptionsOverrideSpec.scala— tests for priority/override semanticsLiveFileOptionsSpecShared.scala— filesystem tests usingTestSystemModified files
CliApp.scala— newrunWithFileArgs/runWithoutFileArgsmethods;runnow uses platform defaultCommand.scala—parsemethods acceptfromFiles: List[FileOptions.OptionsFromFile]parameterOptions.scala—validatemerges file-derived options before CLI args; newmergeFileOptions/mergeFileAndInputOptionshelpersHow it works
CliApp.runWithFileArgsextracts the root command name (e.g.git)FileOptions.getOptionsFromFiles("git")searches for.gitfiles in cwd → parents → homeOptions.validatemerges file defaults with explicit CLI args (CLI wins)Backward compatibility
Command.parsegetsfromFiles: List[FileOptions.OptionsFromFile] = Nil— existing call sites unchangedCliApp.runnow consults dotfiles by default (viaFileOptions.default), but apps that don't have dotfiles see no differenceCliApp.runWithoutFileArgsprovides an explicit opt-out/claim #191