Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Commit

Permalink
Do not raise error if last detection called in non nix projects
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Jul 28, 2023
1 parent 103f5f4 commit 09006c1
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions cmd/nixpkgs-url/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ var (
revision = "rev"
)

func mustGetTargetPath() string {
path, err := nixurl.GetTargetPath()
if err != nil {
log.Fatalf("Failed to get target files: %s", err.Error())
}
if path == "" {
log.Fatalln("Any *.nix files are not found")
}

return path
}

func main() {
const usage = `Usage: nixpkgs-url <subcommand> <flags>
Expand Down Expand Up @@ -63,24 +75,32 @@ $ nixpkgs-url -version`
os.Exit(1)
}

path, err := nixurl.GetTargetPath()
if err != nil {
log.Fatalf("Failed to get target files: %s", err.Error())
}
if path == "" {
log.Fatalln("Any *.nix files are not found")
}

switch os.Args[1] {
case "detect":
err := detectCmd.Parse(os.Args[2:])
if err != nil {
flag.Usage()
}

if *lastFlag {
last, err := nixurl.GetLastVersion()
if err != nil {
log.Fatalf("Getting the last version has been failed: %s", err.Error())
}
if *jumpFlag {
fmt.Println("https://github.com/NixOS/nixpkgs/commit/" + last)
} else {
fmt.Println(last)
}
return
}

path := mustGetTargetPath()
if *targetFlag {
fmt.Println(path)
return
}

if *currentFlag {
current, err := nixurl.GetCurrentVersion(path)
if err != nil {
Expand All @@ -95,18 +115,6 @@ $ nixpkgs-url -version`

return
}
last, err := nixurl.GetLastVersion()
if err != nil {
log.Fatalf("Getting the last version has been failed: %s", err.Error())
}
if *lastFlag {
if *jumpFlag {
fmt.Println("https://github.com/NixOS/nixpkgs/commit/" + last)
} else {
fmt.Println(last)
}
return
}

detectCmd.Usage()
case "bump":
Expand All @@ -119,7 +127,7 @@ $ nixpkgs-url -version`
bumpCmd.Usage()
log.Fatalf("Getting the last version has been failed: %s", err.Error())
}
if err = nixurl.Bump(path, last); err != nil {
if err = nixurl.Bump(mustGetTargetPath(), last); err != nil {
bumpCmd.Usage()
log.Fatalf("Bumping the version has been failed: %s", err.Error())
}
Expand Down

0 comments on commit 09006c1

Please sign in to comment.