github.com/wtfutil/wtf@v0.43.0/app/exit_message.go (about) 1 package app 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 8 "github.com/logrusorgru/aurora/v4" 9 "github.com/olebedev/config" 10 ) 11 12 const exitMessageHeader = ` 13 ____ __ ____ .___________. _______ 14 \ \ / \ / / | || ____| 15 \ \/ \/ / ----| |-----| |__ 16 \ / | | | __| 17 \ /\ / | | | | 18 \__/ \__/ |__| |__| 19 20 the personal information dashboard for your terminal 21 ` 22 23 // DisplayExitMessage displays the onscreen exit message when the app quits 24 func (wtfApp *WtfApp) DisplayExitMessage() { 25 exitMessageIsDisplayable := readDisplayableConfig(wtfApp.config) 26 27 wtfApp.displayExitMsg(exitMessageIsDisplayable) 28 } 29 30 /* -------------------- Unexported Functions -------------------- */ 31 32 func (wtfApp *WtfApp) displayExitMsg(exitMessageIsDisplayable bool) string { 33 // If a sponsor or contributor and opt out of seeing the exit message, do not display it 34 if (wtfApp.ghUser.IsContributor || wtfApp.ghUser.IsSponsor) && !exitMessageIsDisplayable { 35 return "" 36 } 37 38 msgs := []string{} 39 40 msgs = append(msgs, aurora.Magenta(exitMessageHeader).String()) 41 42 if wtfApp.ghUser.IsContributor { 43 msgs = append(msgs, wtfApp.contributorThankYouMessage()) 44 } 45 46 if wtfApp.ghUser.IsSponsor { 47 msgs = append(msgs, wtfApp.sponsorThankYouMessage()) 48 } 49 50 if !wtfApp.ghUser.IsContributor && !wtfApp.ghUser.IsSponsor { 51 msgs = append(msgs, wtfApp.supportRequestMessage()) 52 } 53 54 displayMsg := strings.Join(msgs, "\n") 55 56 fmt.Println(displayMsg) 57 58 return displayMsg 59 } 60 61 // readDisplayableConfig figures out whether or not the exit message should be displayed 62 // per the user's wishes. It allows contributors and sponsors to opt out of the exit message 63 func readDisplayableConfig(cfg *config.Config) bool { 64 displayExitMsg := cfg.UBool("wtf.exitMessage.display", true) 65 return displayExitMsg 66 } 67 68 // readGitHubAPIKey attempts to find a GitHub API key somewhere in the configuration file 69 func readGitHubAPIKey(cfg *config.Config) string { 70 apiKey := cfg.UString("wtf.exitMessage.githubAPIKey", os.Getenv("WTF_GITHUB_TOKEN")) 71 if apiKey != "" { 72 return apiKey 73 } 74 75 moduleConfig, err := cfg.Get("wtf.mods.github") 76 if err != nil { 77 return "" 78 } 79 80 return moduleConfig.UString("apiKey", "") 81 } 82 83 /* -------------------- Messaging -------------------- */ 84 85 func (wtfApp *WtfApp) contributorThankYouMessage() string { 86 str := " On behalf of all the users of WTF, thank you for contributing to the source code." 87 str += fmt.Sprintf(" %s", aurora.Green("\n\n You rock.")) 88 89 return str 90 } 91 92 func (wtfApp *WtfApp) sponsorThankYouMessage() string { 93 str := " Your sponsorship of WTF makes a difference. Thank you for sponsoring and supporting WTF." 94 str += fmt.Sprintf(" %s", aurora.Green("\n\n You're awesome.")) 95 96 return str 97 } 98 99 func (wtfApp *WtfApp) supportRequestMessage() string { 100 str := " The development and maintenance of WTF is supported by sponsorships.\n" 101 str += fmt.Sprintf(" Sponsor the development of WTF at %s\n", aurora.Green("https://github.com/sponsors/senorprogrammer")) 102 103 return str 104 }