⛩️ Powerful yet Minimal Nix Dependency Manager
flake flakes home-manager nixos go nix dependency dependencies
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(yae): update list output mode

Fuwn 253e5560 7dacbe79

+59 -22
+59 -22
yae.go
··· 89 89 Name: "tag-predicate", 90 90 Usage: "Git tag predicate used in identifying latest git source", 91 91 }, 92 + &cli.BoolFlag{ 93 + Name: "silent", 94 + Usage: "Silence output", 95 + }, 92 96 }, 93 97 Action: func(c *cli.Context) error { 94 98 if c.Args().Len() != 2 { ··· 120 124 source.TagPredicate = c.String("tag-predicate") 121 125 } 122 126 123 - if sha256, err := fetchSHA256(source.URI, c.Bool("unpack")); err != nil { 127 + if sha256, err := fetchSHA256(source.URI, c.Bool("unpack"), !c.Bool("silent")); err != nil { 124 128 return err 125 129 } else { 126 130 source.SHA256 = sha256 ··· 156 160 Args: true, 157 161 Usage: "Update one or all sources", 158 162 ArgsUsage: "[name]", 163 + Flags: []cli.Flag{ 164 + &cli.BoolFlag{ 165 + Name: "show-updated-only", 166 + Usage: "Output a newline-seperated list of updated sources, silence other output", 167 + }, 168 + }, 159 169 Action: func(c *cli.Context) error { 170 + showAll := !c.Bool("show-updated-only") 171 + updates := []string{} 172 + 160 173 if c.Args().Len() == 0 { 161 - for key, value := range sources { 162 - if err := updateSource(&sources, key, value); err != nil { 174 + for name, value := range sources { 175 + if updated, err := updateSource(&sources, name, value, showAll); err != nil { 163 176 return err 177 + } else if updated { 178 + updates = append(updates, name) 164 179 } 165 180 } 166 181 } else { 167 182 name := c.Args().Get(0) 168 183 169 - if err := updateSource(&sources, name, sources[name]); err != nil { 184 + if updated, err := updateSource(&sources, name, sources[name], showAll); err != nil { 170 185 return err 186 + } else if updated { 187 + updates = append(updates, name) 171 188 } 172 189 } 173 190 174 191 if err := sources.Save(c.String("sources")); err != nil { 175 192 return err 193 + } 194 + 195 + if !showAll { 196 + for _, update := range updates { 197 + fmt.Println(update) 198 + } 176 199 } 177 200 178 201 return nil ··· 185 208 } 186 209 } 187 210 188 - func fetchSHA256(uri string, unpack bool) (string, error) { 211 + func fetchSHA256(uri string, unpack bool, show bool) (string, error) { 189 212 arguments := []string{"--type", "sha256", uri} 190 213 191 214 if unpack { 192 215 arguments = append([]string{"--unpack"}, arguments...) 193 216 } 194 217 195 - output, err := commandOutput("nix-prefetch-url", arguments...) 218 + output, err := command("nix-prefetch-url", show, arguments...) 196 219 197 220 if err != nil { 198 221 return "", err ··· 203 226 return strings.Trim(lines[len(lines)-2], "\n"), nil 204 227 } 205 228 206 - func commandOutput(name string, args ...string) (string, error) { 229 + func command(name string, show bool, args ...string) (string, error) { 207 230 executable, err := exec.LookPath(name) 231 + out := []byte{} 208 232 209 - cmd := exec.Command(executable, args...) 210 - cmd.Stdin = os.Stdin 211 - cmd.Stderr = os.Stderr 212 - out, err := cmd.Output() 233 + if show { 234 + cmd := exec.Command(executable, args...) 235 + cmd.Stdin = os.Stdin 236 + cmd.Stderr = os.Stderr 237 + out, err = cmd.Output() 238 + } else { 239 + cmd := exec.Command(executable, args...) 240 + out, err = cmd.Output() 241 + } 213 242 214 243 return string(out), err 215 244 } 216 245 217 - func fetchLatestGitTag(source Source) (string, error) { 246 + func fetchLatestGitTag(source Source, show bool) (string, error) { 218 247 if source.Type == "git" { 219 248 repository := "https://github.com/" + strings.Split(source.URI, "/")[3] + "/" + strings.Split(source.URI, "/")[4] 220 - remotes, err := commandOutput("git", "ls-remote", "--tags", repository) 249 + remotes, err := command("git", show, "ls-remote", "--tags", repository) 221 250 222 251 if err != nil { 223 252 return "", err ··· 244 273 return "", fmt.Errorf("source is not a git repository") 245 274 } 246 275 247 - func updateSource(sources *Sources, name string, source Source) error { 276 + func updateSource(sources *Sources, name string, source Source, show bool) (bool, error) { 277 + updated := false 278 + 248 279 if !sources.Exists(name) { 249 - return fmt.Errorf("source does not exist") 280 + return updated, fmt.Errorf("source does not exist") 250 281 } 251 282 252 283 if source.Type == "git" { 253 - tag, err := fetchLatestGitTag(source) 284 + tag, err := fetchLatestGitTag(source, show) 254 285 255 286 if err != nil { 256 - return err 287 + return updated, err 257 288 } 258 289 259 290 if tag != source.Version { 260 - fmt.Println("updated version for", name, "from", source.Version, "to", tag) 291 + if show { 292 + fmt.Println("updated version for", name, "from", source.Version, "to", tag) 293 + } 261 294 262 295 source.Version = tag 296 + updated = true 263 297 264 298 if strings.Contains(source.URITemplate, "{version}") { 265 299 source.URI = strings.Replace(source.URITemplate, "{version}", source.Version, 1) ··· 267 301 } 268 302 } 269 303 270 - sha256, err := fetchSHA256(source.URI, source.Unpack) 304 + sha256, err := fetchSHA256(source.URI, source.Unpack, show) 271 305 272 306 if err != nil { 273 - return err 307 + return updated, err 274 308 } 275 309 276 310 if sha256 != source.SHA256 { 277 - fmt.Println("updated hash for", name, "from", source.SHA256, "to", sha256) 311 + if show { 312 + fmt.Println("updated hash for", name, "from", source.SHA256, "to", sha256) 313 + } 278 314 279 315 source.SHA256 = sha256 316 + updated = true 280 317 } 281 318 282 319 (*sources)[name] = source 283 320 284 - return nil 321 + return updated, nil 285 322 }