You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: implement user configuration file support (issue #107)
Add support for user-level configuration files to set default values for
common command-line options. Configuration is loaded from (in priority order):
1. --config CLI option
2. JPM_CONFIG environment variable
3. ~/.config/jpm/config.yml (XDG standard location)
4. ~/.jpmcfg.yml (fallback location)
Features:
- Configuration for cache, directory, no-links, and repositories options
- Home directory expansion (~/ in paths)
- Graceful degradation if config file cannot be read
- CLI options override config file settings
- Repository merging (config repos + CLI repos)
- Explicit config path via --config or JPM_CONFIG
Implementation:
- Created UserConfig class for YAML config parsing
- Added ConfigMixin for global --config option (follows VerboseMixin pattern)
- Updated DepsMixin to load and use UserConfig
- Added test isolation using JPM_CONFIG env var
- Updated tests to reflect new usage line with --config option
@@ -547,8 +558,8 @@ public Integer call() throws Exception {
547
558
try {
548
559
// Use only unmatched args for pass-through to preserve ordering
549
560
returnJpm.builder()
550
-
.directory(depsMixin.directory)
551
-
.noLinks(depsMixin.noLinks)
561
+
.directory(depsMixin.getDirectory())
562
+
.noLinks(depsMixin.getNoLinks())
552
563
.cacheDir(depsMixin.getCacheDir())
553
564
.appFile(appInfoFileMixin.appInfoFile)
554
565
.build()
@@ -601,17 +612,19 @@ String actionName() {
601
612
}
602
613
603
614
staticclassDepsMixin {
615
+
// Cached user configuration loaded from ~/.config/jpm/config.yml or ~/.jpmcfg.yml
616
+
privatetransientUserConfiguserConfig;
617
+
604
618
@Option(
605
619
names = {"-d", "--directory"},
606
-
description = "Directory to copy artifacts to",
607
-
defaultValue = "deps")
620
+
description = "Directory to copy artifacts to (default: 'deps')")
608
621
Pathdirectory;
609
622
610
623
@Option(
611
624
names = {"-L", "--no-links"},
612
-
description ="Always copy artifacts, don't try to create symlinks",
613
-
defaultValue = "false")
614
-
booleannoLinks;
625
+
description =
626
+
"Always copy artifacts, don't try to create symlinks (default: false)")
627
+
BooleannoLinks;
615
628
616
629
@Option(
617
630
names = {"-r", "--repo"},
@@ -625,10 +638,33 @@ static class DepsMixin {
625
638
"Directory where downloaded artifacts will be cached (default: value of JPM_CACHE environment variable; whatever is set in Maven's settings.xml or $HOME/.m2/repository")
626
639
PathcacheDir;
627
640
641
+
/**
642
+
* Loads and caches the user configuration. Priority: --config option > JPM_CONFIG env var >
643
+
* ~/.config/jpm/config.yml > ~/.jpmcfg.yml.
644
+
*
645
+
* @return The user configuration (never null)
646
+
*/
647
+
UserConfiggetUserConfig() {
648
+
if (userConfig == null) {
649
+
userConfig = UserConfig.read(Main.configFile);
650
+
}
651
+
returnuserConfig;
652
+
}
653
+
654
+
/**
655
+
* Returns the cache directory to use. Priority: CLI option > UserConfig > JPM_CACHE env var
656
+
* > Maven default.
657
+
*
658
+
* @return The cache directory path or null to use Maven default
659
+
*/
628
660
PathgetCacheDir() {
629
661
if (cacheDir != null) {
630
662
returncacheDir;
631
663
}
664
+
PathuserConfigCache = getUserConfig().cache();
665
+
if (userConfigCache != null) {
666
+
returnuserConfigCache;
667
+
}
632
668
StringenvCache = System.getenv("JPM_CACHE");
633
669
if (envCache != null && !envCache.isEmpty()) {
634
670
try {
@@ -642,8 +678,53 @@ Path getCacheDir() {
642
678
returnnull;
643
679
}
644
680
681
+
/**
682
+
* Returns the directory to use for artifacts. Priority: CLI option > UserConfig > hardcoded
0 commit comments