repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
a5c22ce
parent
1f65f3f
author
Eric Bower
date
2024-02-28 03:34:55 +0000 UTC
fixes
1 files changed,  +27, -46
M pgs/wish.go
+27, -46
  1@@ -36,23 +36,23 @@ func getUser(s ssh.Session, dbpool db.DB) (*db.User, error) {
  2 type arrayFlags []string
  3 
  4 func (i *arrayFlags) String() string {
  5-    return "array flags"
  6+	return "array flags"
  7 }
  8 
  9 func (i *arrayFlags) Set(value string) error {
 10-    *i = append(*i, value)
 11-    return nil
 12+	*i = append(*i, value)
 13+	return nil
 14 }
 15 
 16 func flagSet(cmdName string, sesh ssh.Session) (*flag.FlagSet, bool) {
 17 	cmd := flag.NewFlagSet(cmdName, flag.ContinueOnError)
 18 	cmd.SetOutput(sesh)
 19-    write := cmd.Bool("write", false, "apply changes")
 20-    return cmd, *write
 21+	write := cmd.Bool("write", false, "apply changes")
 22+	return cmd, *write
 23 }
 24 
 25 func flagCheck(cmd *flag.FlagSet, posArg string, cmdArgs []string) bool {
 26-    cmd.Parse(cmdArgs)
 27+	_ = cmd.Parse(cmdArgs)
 28 
 29 	if posArg == "-h" || posArg == "--help" || posArg == "-help" {
 30 		cmd.Usage()
 31@@ -61,7 +61,6 @@ func flagCheck(cmd *flag.FlagSet, posArg string, cmdArgs []string) bool {
 32 	return true
 33 }
 34 
 35-
 36 func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
 37 	dbpool := handler.DBPool
 38 	log := handler.Cfg.Logger
 39@@ -124,13 +123,10 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
 40 
 41 			if cmd == "link" {
 42 				linkCmd, write := flagSet("link", sesh)
 43-    			linkTo := linkCmd.String("to", "", "symbolic link to this project")
 44-    			if !flagCheck(linkCmd, projectName, cmdArgs) {
 45-    				return
 46-    			}
 47-
 48-				if write == true {
 49-					opts.Write = true
 50+				opts.Write = write
 51+				linkTo := linkCmd.String("to", "", "symbolic link to this project")
 52+				if !flagCheck(linkCmd, projectName, cmdArgs) {
 53+					return
 54 				}
 55 
 56 				if *linkTo == "" {
 57@@ -149,14 +145,11 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
 58 				return
 59 			} else if cmd == "unlink" {
 60 				unlinkCmd, write := flagSet("unlink", sesh)
 61+				opts.Write = write
 62 				if !flagCheck(unlinkCmd, projectName, cmdArgs) {
 63 					return
 64 				}
 65 
 66-				if write == true {
 67-					opts.Write = true
 68-				}
 69-
 70 				err := opts.unlink(projectName)
 71 				opts.notice()
 72 				opts.bail(err)
 73@@ -167,13 +160,10 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
 74 				return
 75 			} else if cmd == "retain" {
 76 				retainCmd, write := flagSet("retain", sesh)
 77-    			retainNum := retainCmd.Int("n", 3, "latest number of projects to keep")
 78-    			if !flagCheck(retainCmd, projectName, cmdArgs) {
 79-    				return
 80-    			}
 81-
 82-				if write == true {
 83-					opts.Write = true
 84+				opts.Write = write
 85+				retainNum := retainCmd.Int("n", 3, "latest number of projects to keep")
 86+				if !flagCheck(retainCmd, projectName, cmdArgs) {
 87+					return
 88 				}
 89 
 90 				err := opts.prune(projectName, *retainNum)
 91@@ -182,47 +172,38 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
 92 				return
 93 			} else if cmd == "prune" {
 94 				pruneCmd, write := flagSet("prune", sesh)
 95+				opts.Write = write
 96 				if !flagCheck(pruneCmd, projectName, cmdArgs) {
 97 					return
 98 				}
 99 
100-				if write == true {
101-					opts.Write = true
102-				}
103-
104 				err := opts.prune(projectName, 0)
105 				opts.notice()
106 				opts.bail(err)
107 				return
108 			} else if cmd == "rm" {
109 				rmCmd, write := flagSet("rm", sesh)
110+				opts.Write = write
111 				if !flagCheck(rmCmd, projectName, cmdArgs) {
112 					return
113 				}
114 
115-				if write == true {
116-					opts.Write = true
117-				}
118-
119 				err := opts.rm(projectName)
120 				opts.notice()
121 				opts.bail(err)
122 				return
123 			} else if cmd == "acl" {
124 				aclCmd, write := flagSet("acl", sesh)
125-    			aclType := aclCmd.String("type", "", "access type: public, pico, pubkeys")
126-    			var acls arrayFlags
127-    			aclCmd.Var(
128-    				&acls,
129-    				"acl",
130-    				"list of pico usernames or sha256 public keys, delimited by commas",
131-    			)
132-    			if !flagCheck(aclCmd, projectName, cmdArgs) {
133-    				return
134-    			}
135-
136-				if write == true {
137-					opts.Write = true
138+				opts.Write = write
139+				aclType := aclCmd.String("type", "", "access type: public, pico, pubkeys")
140+				var acls arrayFlags
141+				aclCmd.Var(
142+					&acls,
143+					"acl",
144+					"list of pico usernames or sha256 public keys, delimited by commas",
145+				)
146+				if !flagCheck(aclCmd, projectName, cmdArgs) {
147+					return
148 				}
149 
150 				if !slices.Contains([]string{"public", "pubkeys", "pico"}, *aclType) {