Skip to content

Commit

Permalink
Added build version support
Browse files Browse the repository at this point in the history
  • Loading branch information
aurc committed Jul 29, 2022
1 parent 8ceaaa8 commit 5302dfd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ THE SOFTWARE.
package cmd

import (
"github.com/aurc/loggo/internal/loggo"
"os"

"github.com/spf13/cobra"
Expand All @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 2 additions & 0 deletions internal/loggo/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/rivo/tview"
)

var BuildVersion string

type LoggoApp struct {
appScaffold
chanReader reader.Reader
Expand Down
4 changes: 2 additions & 2 deletions internal/loggo/splash_screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ package main

import "github.com/aurc/loggo/cmd"

var version string

func main() {
cmd.BuildVersion = version
cmd.Initiate()
}

0 comments on commit 5302dfd

Please sign in to comment.