summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-22 08:44:49 -0600
committerJeff Carr <[email protected]>2024-11-22 08:44:49 -0600
commit03eb4fb389a671c64c35ca486cfe762fef087eab (patch)
tree1321d3af4ddc8b3e1b1f0f317039dff0b86acdd0
parent3e0e1b4531b45f3399dc6a2e9632bc88b609fa0b (diff)
IsPrivate() and IsReadOnly() seems to workv0.0.3
-rw-r--r--forgeConfig/main.go1
-rw-r--r--human.go35
-rw-r--r--readonly.go20
3 files changed, 46 insertions, 10 deletions
diff --git a/forgeConfig/main.go b/forgeConfig/main.go
index e874304..739fa8b 100644
--- a/forgeConfig/main.go
+++ b/forgeConfig/main.go
@@ -55,6 +55,7 @@ func main() {
GoPath: argv.GoPath,
Writable: argv.Writable,
ReadOnly: argv.ReadOnly,
+ Private: argv.Private,
Directory: argv.Directory,
Favorite: argv.Favorite,
Interesting: argv.Interesting,
diff --git a/human.go b/human.go
index 322e6c2..393e9a3 100644
--- a/human.go
+++ b/human.go
@@ -1,6 +1,11 @@
package forgepb
-import "fmt"
+import (
+ "fmt"
+ "os"
+
+ "go.wit.com/log"
+)
// mostly just functions related to making STDOUT
// more readable by us humans
@@ -13,14 +18,34 @@ func RepoHeader() string {
return "Name Path"
}
-func (all *Repos) StandardHeader() string {
+func standardHeader() string {
return fmt.Sprintf("%-4s %40s %s", "r/w", "Path", "flags")
}
-func (r *Repo) StandardHeader() string {
+func (all *Repos) standardHeader(r *Repo) string {
var flags string
- if r.Private {
+ var readonly string
+ if all.IsPrivate(r.GoPath) {
flags += "(private) "
}
- return fmt.Sprintf("%-4s %40s %s", "true", r.GoPath, flags)
+ if all.IsReadOnly(r.GoPath) {
+ readonly = ""
+ } else {
+ readonly = "r/w"
+ }
+ return fmt.Sprintf("%-4s %-40s %s", readonly, r.GoPath, flags)
+}
+
+// print a human readable table to STDOUT
+func (all *Repos) PrintTable() {
+ if all == nil {
+ log.Info("WTF")
+ os.Exit(0)
+ }
+ log.Info(standardHeader())
+ loop := all.SortByPath()
+ for loop.Scan() {
+ r := loop.Repo()
+ log.Info(all.standardHeader(r))
+ }
}
diff --git a/readonly.go b/readonly.go
index 27e23ee..9d0c1e9 100644
--- a/readonly.go
+++ b/readonly.go
@@ -1,6 +1,8 @@
package forgepb
-import "strings"
+import (
+ "strings"
+)
func (all *Repos) UpdateGoPath(name string, gopath string) bool {
oldr := all.DeleteByPath(name)
@@ -43,6 +45,11 @@ func (all *Repos) IsReadOnly(gopath string) bool {
}
}
+ if match == nil {
+ // log.Info("did not match in IsReadOnly()", gopath)
+ return true
+ }
+
// take the settings from the directory match
if match.Writable {
return false
@@ -63,6 +70,9 @@ func (all *Repos) IsReadOnly(gopath string) bool {
func (all *Repos) IsPrivate(gopath string) bool {
var match *Repo
+ // sort by path means the simple 'match' logic
+ // here works in the sense the last directory match
+ // is the one that is used
loop := all.SortByPath() // get the list of repos
for loop.Scan() {
r := loop.Repo()
@@ -81,11 +91,11 @@ func (all *Repos) IsPrivate(gopath string) bool {
}
}
}
-
- if match.Private {
- return true
+ if match == nil {
+ // log.Info("did not match in IsPrivate()", gopath)
+ return false
}
// otherwise, assume not private
- return true
+ return match.Private
}