IsPrivate() and IsReadOnly() seems to work

This commit is contained in:
Jeff Carr 2024-11-22 08:44:49 -06:00
parent 3e0e1b4531
commit 03eb4fb389
3 changed files with 46 additions and 10 deletions

View File

@ -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,

View File

@ -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))
}
}

View File

@ -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
}