diff --git a/cmd/root.go b/cmd/root.go index 7c45f81..9dbcfca 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,6 +23,7 @@ THE SOFTWARE. package cmd import ( + "github.com/aurc/loggo/internal/loggo" "os" "github.com/spf13/cobra" @@ -42,6 +43,7 @@ logs and a toolset to assist you tailoring the display format.`, // Initiate adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Initiate() { + loggo.BuildVersion = BuildVersion err := rootCmd.Execute() if err != nil { os.Exit(1) diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..ab01e21 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,44 @@ +/* +Copyright © 2022 Aurelio Calegari, et al. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +package cmd + +import ( + "fmt" + "github.com/spf13/cobra" +) + +var BuildVersion string + +// versionCmd represents the stream command +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Retrieves the build version", + Long: `Retrieves the build version.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(BuildVersion) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/internal/loggo/app.go b/internal/loggo/app.go index 65dc301..542e362 100644 --- a/internal/loggo/app.go +++ b/internal/loggo/app.go @@ -29,6 +29,8 @@ import ( "github.com/rivo/tview" ) +var BuildVersion string + type LoggoApp struct { appScaffold chanReader reader.Reader diff --git a/internal/loggo/splash_screen.go b/internal/loggo/splash_screen.go index 0a39e36..88dd935 100644 --- a/internal/loggo/splash_screen.go +++ b/internal/loggo/splash_screen.go @@ -58,10 +58,10 @@ func (t *SplashScreen) makeUIComponents() { t.titleView = tview.NewTextView().SetDynamicColors(true).SetTextAlign(tview.AlignCenter) t.subtitleView = tview.NewTextView().SetDynamicColors(true).SetTextAlign(tview.AlignCenter) t.subtitleView.SetText(fmt.Sprintf(` -[white:black:b]l'oGGo[::-]: [yellow::u]Rich Terminal User Interface for following JSON logs +[white:black:b]l'oGGo %s[::-]: [yellow::u]Rich Terminal User Interface for following JSON logs [gray::-]Copyright © 2022 Aurelio Calegari, et al. [lightgray::u]https://github.com/aurc/loggo -`)).SetBackgroundColor(tcell.ColorBlack) +`, BuildVersion)).SetBackgroundColor(tcell.ColorBlack) } func (t *SplashScreen) renderLogo() { diff --git a/main.go b/main.go index d89b413..1a57425 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,9 @@ package main import "github.com/aurc/loggo/cmd" +var version string + func main() { + cmd.BuildVersion = version cmd.Initiate() }