Skip to content

Commit

Permalink
dont prompt to update if not a tty
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Jan 15, 2023
1 parent 6c19b32 commit d6dcf3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cmd/humanlog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ func newApp() *cli.App {

if shouldCheckForUpdate(c, cfg, statefile) {
if statefile.LatestKnownVersion != nil && statefile.LatestKnownVersion.GT(semverVersion) {
promptToUpdate(semverVersion, *statefile.LatestKnownVersion)
promptedToUpdate = statefile.LatestKnownVersion
if shouldPromptAboutUpdate() {
promptToUpdate(semverVersion, *statefile.LatestKnownVersion)
}
}

req := &checkForUpdateReq{
Expand All @@ -230,7 +232,9 @@ func newApp() *cli.App {
if res.hasUpdate {
alreadyPromptedForSameUpdate := promptedToUpdate != nil && promptedToUpdate.GTE(res.sem)
if !alreadyPromptedForSameUpdate {
promptToUpdate(semverVersion, res.sem)
if shouldPromptAboutUpdate() {
promptToUpdate(semverVersion, res.sem)
}
}
}
default:
Expand Down
10 changes: 7 additions & 3 deletions cmd/humanlog/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ func shouldCheckForUpdate(cctx *cli.Context, cfg *config.Config, state *state.St
if cctx.Args().First() == versionCmdName {
return false // check is done already
}
if !isTerminal(os.Stderr) || !isTerminal(os.Stdout) {
// not in interactive mode
if cfg.SkipCheckForUpdates != nil && *cfg.SkipCheckForUpdates {
return false
}
if cfg.SkipCheckForUpdates != nil && *cfg.SkipCheckForUpdates {
return true
}

func shouldPromptAboutUpdate() bool {
if !isTerminal(os.Stderr) || !isTerminal(os.Stdout) {
// not in interactive mode
return false
}
return true
Expand Down

0 comments on commit d6dcf3b

Please sign in to comment.