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, GoPath: argv.GoPath,
Writable: argv.Writable, Writable: argv.Writable,
ReadOnly: argv.ReadOnly, ReadOnly: argv.ReadOnly,
Private: argv.Private,
Directory: argv.Directory, Directory: argv.Directory,
Favorite: argv.Favorite, Favorite: argv.Favorite,
Interesting: argv.Interesting, Interesting: argv.Interesting,

View File

@ -1,6 +1,11 @@
package forgepb package forgepb
import "fmt" import (
"fmt"
"os"
"go.wit.com/log"
)
// mostly just functions related to making STDOUT // mostly just functions related to making STDOUT
// more readable by us humans // more readable by us humans
@ -13,14 +18,34 @@ func RepoHeader() string {
return "Name Path" return "Name Path"
} }
func (all *Repos) StandardHeader() string { func standardHeader() string {
return fmt.Sprintf("%-4s %40s %s", "r/w", "Path", "flags") 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 var flags string
if r.Private { var readonly string
if all.IsPrivate(r.GoPath) {
flags += "(private) " 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 package forgepb
import "strings" import (
"strings"
)
func (all *Repos) UpdateGoPath(name string, gopath string) bool { func (all *Repos) UpdateGoPath(name string, gopath string) bool {
oldr := all.DeleteByPath(name) 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 // take the settings from the directory match
if match.Writable { if match.Writable {
return false return false
@ -63,6 +70,9 @@ func (all *Repos) IsReadOnly(gopath string) bool {
func (all *Repos) IsPrivate(gopath string) bool { func (all *Repos) IsPrivate(gopath string) bool {
var match *Repo 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 loop := all.SortByPath() // get the list of repos
for loop.Scan() { for loop.Scan() {
r := loop.Repo() r := loop.Repo()
@ -81,11 +91,11 @@ func (all *Repos) IsPrivate(gopath string) bool {
} }
} }
} }
if match == nil {
if match.Private { // log.Info("did not match in IsPrivate()", gopath)
return true return false
} }
// otherwise, assume not private // otherwise, assume not private
return true return match.Private
} }