Skip to content

Commit

Permalink
dont update if already running latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Jan 11, 2023
1 parent 54da726 commit 83920e5
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,48 @@ func newApp() *cli.App {
},
},
{
Name: "update",
Flags: []cli.Flag{},
Name: "update",
Flags: []cli.Flag{
cli.IntFlag{Name: flagAccountId, Value: -1},
cli.IntFlag{Name: flagMachineId, Value: -1},
},
Action: func(cctx *cli.Context) error {
apiURL := cctx.GlobalString(flagAPIURL)
updateClient := cliupdatev1connect.NewUpdateServiceClient(client, apiURL)
accountId := cctx.Int64(flagAccountId)
machineId := cctx.Int64(flagMachineId)
res, err := updateClient.GetNextUpdate(ctx, connect.NewRequest(&cliupdatepb.GetNextUpdateRequest{
ProjectName: "apictl",
CurrentVersion: version,
AccountId: accountId,
MachineId: machineId,
MachineArchitecture: runtime.GOARCH,
MachineOperatingSystem: runtime.GOOS,
}))
if err != nil {
return err
}
msg := res.Msg

if msg.Account != nil && accountId != msg.Account.Id {
log.Printf("an account id was assigned: %d", msg.Account.Id)
}
if msg.Machine != nil && machineId != msg.Machine.Id {
log.Printf("a machine id was assigned: %d", msg.Machine.Id)
}

currentSV, err := version.AsSemver()
if err != nil {
return err
}
nextSV, err := msg.NextVersion.AsSemver()
if err != nil {
return err
}
if currentSV.GTE(nextSV) {
log.Printf("you're already running the latest version: v%v", semverVersion.String())
return nil
}
return selfupdate.UpgradeInPlace(ctx, "apictl", os.Stdout, os.Stderr, os.Stdin)
},
},
Expand Down

0 comments on commit 83920e5

Please sign in to comment.