Skip to content

Commit

Permalink
feat: Add ability to use ~ tidle in configuration file
Browse files Browse the repository at this point in the history
We no longer need to provide absolute paths in the configuraion
file.  This does not affect the defaults.
  • Loading branch information
lcook committed Sep 1, 2023
1 parent 6afe87b commit 5d0a895
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions .portsync.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Path to your local ports directory.
#base = "/usr/ports"
#base = "/usr/ports" # Default
#base = "~/git/ports"

# Default maintainer used by portscout.
#maintainer = "ports@FreeBSD.org"
#maintainer = "ports@FreeBSD.org" # Default

# By default all packages associated with a
# maintainer are used. You can limit this
Expand All @@ -12,4 +13,5 @@

# Location in which the Makefile scripts
# are located.
#scriptDir = "/usr/lcoal/share/portsync/Mk"
#scriptDir = "/usr/lcoal/share/portsync/Mk" # Default
#scriptDir = "~/Mk"
5 changes: 5 additions & 0 deletions internal/fetcher/portscout.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"sync"
Expand Down Expand Up @@ -87,6 +88,10 @@ func (ps Portscout) Fetch(cmd *cobra.Command) (*Packages, error) {

func (ps Portscout) Transform(cmd *cobra.Command, pkg *Package) (*Package, error) {
base := viper.GetString("base")
if strings.HasPrefix(base, "~/") {
dir, _ := os.UserHomeDir()
base = filepath.Join(dir, base[2:])
}
if !strings.HasSuffix(base, "/") {
base += "/"
}
Expand Down
9 changes: 9 additions & 0 deletions internal/mk/mk.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package mk
import (
"os"
"os/exec"
"path/filepath"
"strings"

. "github.com/lcook/portsync/internal/_package"
Expand All @@ -17,6 +18,10 @@ import (

func run(pkg *Package, makefile string) {
base := viper.GetString("base")
if strings.HasPrefix(base, "~/") {
dir, _ := os.UserHomeDir()
base = filepath.Join(dir, base[2:])
}
if !strings.HasSuffix(base, "/") {
base += "/"
}
Expand All @@ -31,6 +36,10 @@ func run(pkg *Package, makefile string) {
os.Setenv(k, v)
}
scriptDir := viper.GetString("scriptdir")
if strings.HasPrefix(scriptDir, "~/") {
dir, _ := os.UserHomeDir()
base = filepath.Join(dir, scriptDir[2:])
}
if !strings.HasSuffix(scriptDir, "/") {
scriptDir += "/"
}
Expand Down

0 comments on commit 5d0a895

Please sign in to comment.