mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
+ Add controller interface + Add renderable interface - A controller define his store. And Running cycle returning a renderable interface - Json is handle between Run & Render is the proper flag is set
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package version
|
|
|
|
import (
|
|
fctl "github.com/formancehq/fctl/pkg"
|
|
"github.com/pterm/pterm"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
Version = "develop"
|
|
Commit = "-"
|
|
BuildDate = "-"
|
|
)
|
|
|
|
type VersionStore struct {
|
|
Version string `json:"version"`
|
|
BuildDate string `json:"buildDate"`
|
|
Commit string `json:"commit"`
|
|
}
|
|
type VersionController struct {
|
|
store *VersionStore
|
|
}
|
|
|
|
var _ fctl.Controller[*VersionStore] = (*VersionController)(nil)
|
|
|
|
func NewDefaultVersionStore() *VersionStore {
|
|
return &VersionStore{
|
|
Version: Version,
|
|
BuildDate: BuildDate,
|
|
Commit: Commit,
|
|
}
|
|
}
|
|
|
|
func NewVersionController() *VersionController {
|
|
return &VersionController{
|
|
store: NewDefaultVersionStore(),
|
|
}
|
|
}
|
|
|
|
func NewCommand() *cobra.Command {
|
|
return fctl.NewCommand("version",
|
|
fctl.WithShortDescription("Get version"),
|
|
fctl.WithArgs(cobra.ExactArgs(0)),
|
|
fctl.WithController[*VersionStore](NewVersionController()),
|
|
)
|
|
}
|
|
|
|
func (c *VersionController) GetStore() *VersionStore {
|
|
return c.store
|
|
}
|
|
|
|
func (c *VersionController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
|
|
return c, nil
|
|
}
|
|
|
|
// TODO: This need to use the ui.NewListModel
|
|
func (c *VersionController) Render(cmd *cobra.Command, args []string) error {
|
|
tableData := pterm.TableData{}
|
|
tableData = append(tableData, []string{pterm.LightCyan("Version"), c.store.Version})
|
|
tableData = append(tableData, []string{pterm.LightCyan("Date"), c.store.BuildDate})
|
|
tableData = append(tableData, []string{pterm.LightCyan("Commit"), c.store.Commit})
|
|
return pterm.DefaultTable.
|
|
WithWriter(cmd.OutOrStdout()).
|
|
WithData(tableData).
|
|
Render()
|
|
}
|