Skip to content

Commit

Permalink
fix: improve version info
Browse files Browse the repository at this point in the history
Fixes #29
  • Loading branch information
starpit committed Oct 22, 2019
1 parent 1f35f52 commit 8196c77
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
25 changes: 10 additions & 15 deletions kui/kui.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import (
"strings"
)

// version information that will come from goreleaser
var (
version = "dev"
commit = "none"
date = "unknown"
)

type KrewComponent interface {
init()
}
Expand All @@ -46,6 +39,9 @@ const PLUGIN_VERSION = "dev"
const defaultCommandContext = "plugin"

type MainContext struct {
version string
commit string
date string
_logger *log.SugaredLogger
}
func (context MainContext) PluginDirectory() (string, error) {
Expand All @@ -68,19 +64,18 @@ func initLogger()(*log.Logger, error) {
return log.NewProduction()
}
}
func (context *MainContext) initDefault()(*MainContext) {
func initDefault(version string, commit string, date string)(MainContext) {
logger, err := initLogger()
if err != nil {
baselog.Fatalf("can't initialize zap logger: %v", err)
}
context._logger = logger.Sugar()
return context
_logger := logger.Sugar()
return MainContext{ version, commit, date, _logger }
}

func Start() {
func Start(version string, commit string, date string) {
runner := KuiComponent{}
context := MainContext{}
context.initDefault()
context := initDefault(version, commit, date)
runner.Run(context, os.Args)
}

Expand All @@ -106,7 +101,7 @@ const (
)
type ExecStyle int

func (component *KuiComponent) Run(context Context, args []string) {
func (component *KuiComponent) Run(context MainContext, args []string) {
component.init()

if len(args) == 1 || (len(args) == 2 && (args[1] == "-h" || args[1] == "--help")) {
Expand Down Expand Up @@ -167,7 +162,7 @@ func (component *KuiComponent) Run(context Context, args []string) {

if arg == "version" {
// also report our version
fmt.Printf("%v\t%v %v\n%v\t", blue(base), version, date, blue("kui"))
fmt.Printf("%v\t%v %v\n%v\t", blue(base), context.version, context.date, blue("kui"))
}

component.invokeRun(context, cmd, kaskArgs, style)
Expand Down
3 changes: 2 additions & 1 deletion kui/kui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ func (suite *KaskTestSuite) TestRunDownload() {
}

func createDefaultFakePluginContext(saveDir string) *MainContext {
return new(MainContext).initDefault()
context := initDefault("dev", "", "unknown")
return &context
}
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import (
"github.com/kui-shell/kask/kui"
)

// version information that will come from goreleaser
var (
version = "dev"
commit = "none"
date = "unknown"
)

func main() {
kui.Start()
kui.Start(version, commit, date)
}

0 comments on commit 8196c77

Please sign in to comment.